Serial Port Help

Could someone help me with getting information from my serial port? I really have no experience with Serial port communication and need a ton of assistance. The examples Xojo provided are not pertinent to what I am attempting to accomplish.

Objective:

There is a Pressure Transducer that provides pressures to the computer via serial port. I want those to become a global variable in my program that many different items can refer to.

Current Progress:

The code to acquire the pressures is !001:SYS?

Baud rate = 115200
Data bits = 8
Stop Bits = 1
Parity = None
CTS = Off
DTR = Off
XON = Off
Initial Line Status = DTR (Off) RTS (Off)

Notes:

I am sorry for the lack of knowledge. Serial ports seem to be another beast entirely. An example would be very beneficial as a spring board.

Thank you so much ahead of time.

Have you read the documentation on the Serial class in Xojo? I hate to be that guy, but what you need to do is covered relatively well there.

The basic gist of it is that you’ll need to construct an instance of Serial, set it up with the settings you have indicated above, then write your command to it with the write() method, and handle the dataAvailable() event to receive your response.

Also, check out the examples under the Example Projects/Communication/Serial folder in your Xojo installation.

[quote=168752:@Jukka Leino]If you open this example Line State Change Tester, add there DataAvailable event to TestSerial with code:

TextArea1.AppendText me.ReadAll(Encodings.ISOLatin1) + EndOfLine

and add also TextArea component.
Then if You have serialport settings right (baud, bits, parity etc.), it should read from device.[/quote]

Add also in WatchButton action event to last line:

TestSerial.Write("!001:SYS?")

Those bauds, bits and stops You can enter from inspector if TestSerial is selected.

This should work or at least guide You to right direction.

Jukka

I have not tested in a while, but if you are relying on RTS to change the state of your hardware, don’t. It did not work properly before. it has been quite a while since I looked at this, but asserting rts high, when looked at with a scope did funky things. like go hi then low then high again. Enough to kill the data stream.

search the real software forum, or the feedback. it was detailed in both places by myself and another user at the time.

Tim

[quote=173896:@Jukka Leino]Add also in WatchButton action event to last line:

TestSerial.Write("!001:SYS?")

Those bauds, bits and stops You can enter from inspector if TestSerial is selected.

This should work or at least guide You to right direction.

Jukka[/quote]

Thank you so much. This is a very thorough example that really will help me. So when I edit the example like you stated, will it populate the TextArea with the response? How will I know what the response is?

Response (and commands for device) you have to look from device manual.
But yes, as long this “!001:SYS?” is correct, response will come to textarea.

[quote=174034:@Jukka Leino]Response (and commands for device) you have to look from device manual.
But yes, as long this “!001:SYS?” is correct, response will come to textarea.[/quote]

Could it be that it needs to be in Hex?

{33, 48, 48, 49, 58, 115, 121, 115, 63, 13}

Okay, While working on this, here is my current code that relates to the Serial Port:

PopupMenu1 - Change

[code] If Me.ListIndex = -1 Then Return

SerialPort1.SerialPort = System.SerialPort( Me.ListIndex )

If Not SerialPort1.Open Then
MsgBox("Couldn’t open the device: " + Str( SerialPort1.LastErrorCode ))
End If[/code]

PopupMenu1 - Open

[code] Me.ListIndex = -1

Dim count As Integer
count = System.SerialPortCount

For i As Integer = 0 To count - 1
Me.AddRow( System.SerialPort( i ).Name )
Next[/code]

GraphicalRefreshTimer - Action

If PopupMenu1.ListIndex < 0 Then [b]<CR> = endofline.unix[/b] dim s as string = "!001:SYS?" + endofline.unix serialPort1.write s end

SerialPort1 - DataAvailable

[b]CurrentPressure = me.ReadAll(Encodings.ISOLatin1) + EndOfLine [/b]

The bolded code is were the bugs are. What did I do incorrectly? Teach me please. Thank you!