Serial Value Fetching

Hello,
I am new to Xojo, but have various programming experience. In that experience, I never worked with serial ports and communicating with USB. In my current project, that is where I am having issues. I am attempting to fetch numerical values from a device and return them to a listbox that will be the source for a graph using the monkeybread plugin.

Could someone walk me through what steps to take to accomplish this task? I am struggling. Thanks!

[quote=168350:@Meade Lewis]Hello,
I am new to Xojo, but have various programming experience. In that experience, I never worked with serial ports and communicating with USB. In my current project, that is where I am having issues. I am attempting to fetch numerical values from a device and return them to a listbox that will be the source for a graph using the monkeybread plugin.

Could someone walk me through what steps to take to accomplish this task? I am struggling. Thanks![/quote]

What have you got so far ?

Hi

First you open serialport like in Examples/Communication/Serial

then you put in DataAvailable event in serial some code to read data.

There is example from my code:

 if ascdec(0).Value then
    dim chrarr(-1) As  String
    chrarr=Split(me.ReadAll(Encodings.ISOLatin1), "")
    TextArea1.AppendText "Receiving: "
    For Each chrs as String in chrarr
      TextArea1.AppendText Str(Asc(chrs)) + " "
    next
    TextArea1.AppendText Chr(13)
  else
    TextArea1.AppendText "Receiving: " +me.ReadAll(Encodings.ISOLatin1) + EndOfLine
  end if

I have radiobutton (ascdec) to select if I want ascii text or decimal values of characters.
And then I put this on TextArea, you can put it on listbox as well.

You can also use timer and Serial1.LookAhead to see if there is something and read with Serial1.ReadAll if You don’t want to use DataAvailable event.

Jukka

[quote=168532:@Jukka Leino]Hi

First you open serialport like in Examples/Communication/Serial[/quote]

This might sound like a dumb question, but where do I find the examples?

Isn’t the point of the Baud a delay of reading time?

Click help in the IDE, then Examples in the left column.

Or look right next to the Xojo program. In Applications on Mac, in C:\Program Files(x86) on PC.

Baud is the communication speed. Not a delay.

[quote=168618:@Michel Bujardet]Click help in the IDE, then Examples in the left column.

Or look right next to the Xojo program. In Applications on Mac, in C:\Program Files(x86) on PC…[/quote]

Found it and am studying it. Thank you for the direction.

[quote=168532:@Jukka Leino]Hi

First you open serialport like in Examples/Communication/Serial[/quote]

So: [quote] [code] Dim count As Integer
count = System.SerialPortCount

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

Found in the open event handler?

[quote=168532:@Jukka Leino]then you put in DataAvailable event in serial some code to read data.

I have radiobutton (ascdec) to select if I want ascii text or decimal values of characters.
And then I put this on TextArea, you can put it on listbox as well.[/quote]

I will be using ascii

Could you explain this a little more clearly?

Thank you so much for all of your help. I really need it!

[quote=168698:@Meade Lewis]So:

Dim count As Integer
count = System.SerialPortCount

For i As Integer = 0 To count - 1
SerialPortPopup.AddRow( System.SerialPort( i ).Name )
Next
Found in the open event handler?

[/quote]

That is only for listing available ports to popupmenu.
See WatchButton Action event for opening port. It’s commented there.

I think You should read Tutorial and Userguide from Help menu.

Btw. What is this device you connect, and have you tryed to read from it with some serial debugger?

[quote=168728:@Jukka Leino]That is only for listing available ports to popupmenu.
See WatchButton Action event for opening port. It’s commented there.

I think You should read Tutorial and Userguide from Help menu.

Btw. What is this device you connect, and have you tryed to read from it with some serial debugger?[/quote]

I am trying to connect a pressure transducer. I got the user guide and have been studying all day.

What debugger would you suggest?

Try CoolTerm
http://freeware.the-meiers.org/

And 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.

Any link we can follow to check the device?

I have code for communication with modbus devices if you’re interested…
Send me a personal message.

Kato

Still picking which transducer would be best for us. The CEO just switched which one he wanted to standardize with.

Interesting. I will PM you.

So I will be able to check what with this? It seems to be its own software, not something I can merely add in.

[quote=168752:@Jukka Leino]
And 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]
Rock on! I will try this. Thank you so much

To everyone: Thank you so much for your continued support. I am new to Xojo and I am glad to have found a community of good people looking to help the “new kid on the block”.

[quote=169036:@Meade Lewis]@Jukka Leino Try CoolTerm
http://freeware.the-meiers.org/
So I will be able to check what with this? It seems to be its own software, not something I can merely add in.[/quote]

When you attach your device to computer, it propably shows as serialport.
With CoolTerm you can see what is this new port on your computer.
Then you can connect to this port with coolterm and also read from it.
And if you can connect with CoolTerm, you can connect with xojo with same settings.

If the device does not show as serialport, this case is more difficult.
In this case you can try mbs usb plugins or maybe device manufacturer has some librarys to communicate with device.

But I don’t know what device it is, so it’s only guessing.

[quote=169054:@Jukka Leino]When you attach your device to computer, it propably shows as serialport.
With CoolTerm you can see what is this new port on your computer.
Then you can connect to this port with coolterm and also read from it.
And if you can connect with CoolTerm, you can connect with xojo with same settings.

If the device does not show as serialport, this case is more difficult.
In this case you can try mbs usb plugins or maybe device manufacturer has some librarys to communicate with device.

But I don’t know what device it is, so it’s only guessing.[/quote]

Because the device runs off of a call to in order for the computer to obtain a response, I do not know what it is responding with. The information that I got from CoolTerm is as follows:

It is a serial in Com port 3, 9600 Baud, 8 Data bits, no Parity, 1 stop bit. Other than that, the RTS, DTR, and CTS signals were highlighted.

Thanks again for your help.

This is why I asked for a link to information on the device. Before talking about specific code, it would be good to be sure we are trying to access the device properly. This is also why Jukka asked whether you can see and connect to the device using a COM port analysis tool.

Sorry, I thought you were asking for specifics which I do not know right now. The device that I took the information above off of was one that is currently in the facility.

[quote=169104:@Meade Lewis]Because the device runs off of a call to in order for the computer to obtain a response, I do not know what it is responding with. The information that I got from CoolTerm is as follows:

It is a serial in Com port 3, 9600 Baud, 8 Data bits, no Parity, 1 stop bit. Other than that, the RTS, DTR, and CTS signals were highlighted.
.[/quote]

Usually such a device will come with instructions about the communication protocol, which commands you can send in, and which responses the device is supposed to reply with.

If you want to go anywhere, you must have specifics about the device you want to communicate with. If it is the device at your facility you experiment with, get the proper documentation for it before proceeding.

I made this test project a long time ago. It has no documentation nor error checking… but can help you get started. You can use it to connect to the device, send messages and read the data received by the computer.

https://dl.dropboxusercontent.com/u/3800071/COMCheck.xojo_binary_project

Julen

[quote=169109:@Michel Bujardet]Usually such a device will come with instructions about the communication protocol, which commands you can send in, and which responses the device is supposed to reply with.

If you want to go anywhere, you must have specifics about the device you want to communicate with. If it is the device at your facility you experiment with, get the proper documentation for it before proceeding.[/quote]

The command to read pressure is ! 0 0 1 : S Y S ? if that helps.

Thanks brother. I will try it out when I get the chance.

I am not trying to do it for you. You have to study what the device returns, what are the commands to send like that one for the device to work, and build your app based on that.

You may want to start by writing down all the commands needed by your future application, the possible responses from the device including errors, and this will give you a more complete picture as what you need to do.