Jump to content

RS232 - hex string command communication


pockey

Recommended Posts

Hello, all, I'm totally new to LabVIEW. I'm now going to convert a serial communication developed with C# to LabVIEW.

However, I'm unfamiliar with LabVIEW at all and do not know how to convert the programme in a short time.

The deadline is tomorrow and I did not have time to learn LabVIEW from the very beginning. There is too much information and I could not find what I need only for this project.

I know that I should use VISA for the RS-232, however, I did not know how to make the program check the COM Port by itself, the default is COM1. But in my computer, the right one is COM3 or COM4...Is there such funtion to automatically check all avaiable and connected COM ports by itself??

In C#, user should first open the port, and then begin write to or read from the port. LabVIEW will immediately read fom the COM port, right??

When I open the port in C#, there will be a menu of commands from the connected board, the GUI is shown:

2427tester.gif

I need to develop a LabVIEW front panel similar as above.

Does LabVIEW have "textarea" which shows the message received from the COM Port? And "Group" to put "buttons" together?

I can see there is a lot of controls and functions, however, to find the right one is time-consuming for me, could anyone tell me the name and location of the controls in LabVIEW corresponding to "buttons", "textarea", "group", "combobox"...in Visual Studio?

And when I press the button, it will send a string to the COM Port, some buttons send more than one command, so there should be some delay between these commands, in C#, I use "Thread.sleep(100)" as the delay time...How to implement this in LabVIEW??

Thanks!

Link to post

It seems all the buttons in LabVIEW are boolean values...

In C#, button has event which can be implemented to send command to the COM Port, how to get the same result with LabVIEW???

Is there any similar examples for RS232 communication??

Thanks a lot!

Link to post
The deadline is tomorrow

You can't learn a language in one day...

Some things even work competely different in labview than in any text based language. For example: your connections dictate the execution sequence, but by default everything is executed in parallel...

I know that I should use VISA for the RS-232, however, I did not know how to make the program check the COM Port by itself, the default is COM1. But in my computer, the right one is COM3 or COM4...Is there such funtion to automatically check all avaiable and connected COM ports by itself??

No you have to do that yourself. You could iterate over the COMx ports and send something and check what comes back. You can format a string in a C like way with Format Into String, so you can build a "COMx" string and wire that to the VISA function.

In C#, user should first open the port, and then begin write to or read from the port. LabVIEW will immediately read fom the COM port, right??

On itself that's true but you probably need to set the speed etc first anyway.

I need to develop a LabVIEW front panel similar as above.

Does LabVIEW have "textarea" which shows the message received from the COM Port? And "Group" to put "buttons" together?

Yes, you can find it on the palette. Because the string indicator/control can be resized and given a scrollbar.

You could use an event handler to handle the button presses and typed texts.

You could continuously set the cursor at the last position in the text so that it "types" like a terminal.

And when I press the button, it will send a string to the COM Port, some buttons send more than one command, so there should be some delay between these commands, in C#, I use "Thread.sleep(100)" as the delay time...How to implement this in LabVIEW??

No problem. Have a look in the help and examples. Wiring the error wire through is the best way to make a sequence of actions. One of those action could be a wait function.

For your each specific problem search the NI forums: forums.NI.com

There is lots of info on communicating with devices in various protocols.

Success,

Joris

Link to post

Thanks a lot, robijn, for your long and detailed answers, it shows me the direction and ways to develop my programme.

I know I could not learn a language in one day, however, I had to complete the convertion in one day this time~~~ :headbang:

I'll try to learn to use the functions you mentioned here.

Another question: what is the character for the "Enter" key?

For example, to reset the connected board, user should send the string "x" with pressing "Enter" key. In HyperTerminal, after key-in "x", user has to press the "Enter" key to send the "x" to reset the board.

For easy use, after user press the button, the string "x" together with the character representing "Enter" key should be sent. In C#, I use

String s = "x" +'\r'; so '\r' stands for the "Enter" key action, I could not write String s = "x\r"; which won't work.

So in LabVIEW, if I want to send string "x" together with the "Enter" key character, what should I do?

And for the event of button, where could I find such information??

Link to post
Another question: what is the character for the "Enter" key?

On modem-like connections it's usually \r (carriage return). There's a constant for it in the palette.

You can place the \r and \n chars the Format Into String format input as well.

I could not write String s = "x\r"; which won't work.

You could, if you set \-mode for the control or constant.

And for the event of button, where could I find such information??

Help on event structure.

(Can't imagine my answers are long... ;) )

Joris

Link to post
Yes, you can find it on the palette. Because the string indicator/control can be resized and given a scrollbar.

Well, is there append function to show all the information instead of only showing the latest information? Since we can use the scrollbar to move up and down?

You could use an event handler to handle the button presses and typed texts.[\quote]

I still do not know how to solve the problem...

With the help of avaiable examples of "Basic Serial Write and Read.vi", I could communicate with my board now. However, it's still a big question for me to use event handler. I hope by simply pressing a button, the program will run and send the command. By now, I could only first key-in the commands in the "String to Write" control and then press the "Run" button to begin sending the commands, it is troublesome. Is there any way to send the commands by just pressing the "Enter" key after key-in the commands?? It's quite discommodious to press the "Run" button every time sending commands to the board.

The better solution I want is just press the buttons, the programe will run and the corresponding commands will be sent to the board. However, I have no idea how to realize that..

serial.GIF

The front panel is shown above, I hope to add the buttons on the right panel for easy use...

serialblock.GIF

Could anyone show me how to do the button event handler? One button is OK for me learn from.

Download File:post-6631-1168486291.llb

Link to post

You have now three actions in a single VI, and you cannot perform multiple actions triggered by buttons.

1. You need to split this into three subVIs: open device, query device and close device. (replace "device" by the name of your device.)

1.1 Create subVI's for them. Test them by running them individually.

1.2 Give them the connector pane with 12 connections (default in LV8)

1.3 Connect the connector pane. Connect the error connectors and text/data input/output connectors. Keep left for input and right for output. Connect error in and error out to the bottom left and right connector.

1.4 Give them an icon with short text describing their function.

2. Create the basis for a "real" program.

2.1 You will at least need a while loop.

2.2 Better would be to use what is called a Queued Message Handler. I've attached a simple template of one, that you could use. Read more on how QMH's work on the NI site or maybe on this site. It's a template only, you will need to adapt the VI to suit your needs.

2.3 Add the button actions in the user event handling part of the QMH. Create new separate actions by modifying the Type definition of the enum. Call those actions from the event structure.

2.4 When doing the actual actions for the buttons, in the frames of the case structure, call the "query device" VI created in step 1 to perform the communication.

2.5 You can update the string indicator by storing the full communication transcript in the state shift register of the QMH, and appending new data to that string when it arrives. You will need to find out how a shift register works and how bundling and unbundling clusters works. Update the string on the front panel by calling the update display state.

How to actually do many of these things will cost some time to find out yourself, but I hope I can give you some line of what things need to be done, what direction to go. Work these points one by one. If you cannot do a next point, you did not study the previous point sufficiently ;)

If you manage to do all this you have a pretty decent program.

Joris

Download File:post-1555-1168506856.zip

Link to post

Thanks a lot, Robijn

There are many concepts in your answer I need to get to know.

I tried some buttons, however, the program can only now run once, and user has to press the button first and then click the "Run" button to send commands. When I add while loop, the string indicator could now show the message correctly...

I'm looking for the method to append new message to the original one and show them all in the string indicator. I'll have a look at the register.

For your suggestion, I'll try them one by one.

Link to post

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.