text to com1

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
hi to all,
i am trying to senf string to com1 where LCD device is connected.
my code:
<pre class="prettyprint port.PortName = "COM1";
port.BaudRate = 9600;
port.Parity = Parity.None;
port.DataBits = 8;
port.StopBits = StopBits.One;
port.Open();
port.Write(textBox1.Text);
port.Close();[/code]
but nothing appears in my lcd device.
The manufacturer has an example in VB thats works just fine:
<pre class="prettyprint lang-vb Private Sub Command1_Click()
Buffer to hold input string
Dim Instring As String
Use COM1.
MSComm1.CommPort = 1
9600 baud, no parity, 8 data, and 1 stop bit.
MSComm1.Settings = "9600,N,8,1"
Tell the control to read entire buffer when Input
is used.
MSComm1.InputLen = 0
Open the port.
MSComm1.PortOpen = True
Send the attention command to the modem.

MSComm1.Output = "0x20x01TEST MESSAGE0x03"
Dim exo As Variant
exo = "0x20"
exo = Chr(2) & "?NUOAEECIA IAIA OOII ?AENAEA " & Chr(3)
MSComm1.Output = exo

For i = 1 To 1
MSComm1.Output = Chr(2) & 1 & Chr(3)
MSComm1.Output = Chr(2) & Chr(0) & "abcdefghijklmnop" & Chr(3)
MSComm1.Output = Chr(2) & Chr(1) & "1234567890123456" & Chr(3)
MSComm1.Output = Chr(2) & Chr(0) & "ABCDEFGHIJKLMNOP" & Chr(3)
MSComm1.Output = Chr(2) & Chr(1) & "010203040506070809" & Chr(3)

Next i

Dim a(4) As String
Do
DoEvents
buffer$ = buffer$ & MSComm1.Input
For i = 1 To Len(buffer$)
a(i) = Asc(Mid(buffer$, i, 1))
Next i
Loop Until InStr(buffer$, Chr(19))
Read the "OK" response data in the serial port.
Close the serial port.



MSComm1.PortOpen = False

End Sub
[/code]

what i am doing wrong?
Thanks in advance







View the full article
 
Back
Top