DMX 512 receiver , i need to send data in 512 lines through serial port communication .The problem arises when i need to send data at a baud rate 250000 . Then i used DCB Control block with Getcomm state and Set Comm state . and then i writefile but should i use comPort.Write (Serial comPort = new Serial Port) to send data or WriteFile .This is my below program
I have a VB.Net program of Serial Port communication program of sending data to DMX 512 receiver which i need to convert into c# . But i am confused as they have used MSCOMM1.OUTPUT to send data .
Your help highly appreciated
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Public data_array
Private Sub cmd_Start_Click()
setup_com_port
send_comm_data
End Sub
Private Sub cmd_Stop_Click()
If MSComm1.PortOpen = True Then
End
End If
End Sub
Private Sub Form_Load()
data_array = Array(&H7, &H20, &H7)
Slider_Red = &H7
Slider_Green = &H20
Slider_Blue = &H7
End Sub
Private Sub setup_com_port()
MSComm1.CommPort = 2
MSComm1.Settings = "9600,N,8,2"
MSComm1.PortOpen = True
SetBaudRate MSComm1, 250000
End Sub
Sub SetBaudRate(Com As MSComm, baud As Long)
Dim ComDcb As dcb
Dim ret As Long
If Not Com.PortOpen Then
Err.Raise comPortNotOpen, Com.Name, _
"Operation valid only when the port is open"
Exit Sub
End If
ret = GetCommState(Com.CommID, ComDcb)
If ret = 0 Then
Err.Raise comDCBError, Com.Name, _
"Could not read current state of the port"
Exit Sub
End If
ComDcb.BaudRate = baud
ret = SetCommState(Com.CommID, ComDcb)
If ret = 0 Then
Err.Raise comSetCommStateFailed, Com.Name, _
"Could not set port to specified baud rate"
Exit Sub
End If
End Sub
Private Sub send_comm_data()
Do
com_break (5)
Sleep (5)
MSComm1.Output = Chr$(0)
send_char_0
Sleep (10)
DoEvents
Loop
End Sub
Private Sub com_break(break_in_ms)
MSComm1.Break = True
Sleep (1)
MSComm1.Break = False
End Sub
Private Sub send_char_0()
Dim strData As String
strData = ""
For i = 0 To UBound(data_array)
strData = strData & Chr$(data_array(i))
Next
For i = 1 To 509
strData = strData & Chr$(50)
Next
MSComm1.Output = strData
7 DoEvents
End Sub
Thanks in advance