Instrument Control (GPIB, Serial, VISA, IVI)

cancel
Showing results for 
Search instead for 
Did you mean: 

Send command to laser sensor via serial port RS232

Solved!
Go to solution

Hi,

 

I've got a Laser displacement sensor of OPTEX FA Co., LTD with a Communication Manual.pdf file attached. I modified the Basic Serial Write and Read.vi sample from LV to send command to the sensor in order to receive a response. However, LV always returns an error on my VISA Write.

 

In brief, the command structure send to the sensor should have a form like this

       STX-Command 1-Space-Command 2-ETX

       (details could be refer to the Manual on page 3 or page 18 of the .pdf file)

where

- STX: code showing the head of transmit data (02H)

- Command 1, 2: could be refers to the Table 1, 2, , and 3 of the manual.

- ETX: code showing the completion of transmit data (03H)

 

For example, if I want to ask the sensor to send the measurement data of the sensor head A, the command should be

      STX-MEASURE()A-ETX

The space (20H) is shown as ().

I've tried to send a HEX string (02-4D454153555245-20-41-03) of this command to the VISA Write but everything I receive is ERROR.

 

I also attach with this thread my vi and a printscreen of the ERROR.

Much much appreciation for any help from any of you.

0 Kudos
Message 1 of 19
(7,467 Views)

hi

please replace the stacked sequence by a normal sequence, then remove the sequence structure completely and wire the error out of each visa write to the error in of the next. LabVIEW has sequencing by wire so in this vi you don't need a sequence structure.

The next step is to replace the com1 string constant by a visa resource control on the frontpanel.

and select the serial port that connects to your device.

Now switch debugging on and look carefully where it goes wrong. 

greetings from the Netherlands
0 Kudos
Message 2 of 19
(7,465 Views)

Your string controls are also setup incorrectly. You want Hex Display.

0 Kudos
Message 3 of 19
(7,460 Views)

Hi Albert,

 

Thank you so so much for your prompt help. I highly appreciate for your enthusiast.

 

I've followed your instruction to modify my vi, however the result looks like the same. I'm not sure for transfering the whole command using HEX string in my way is right or wrong. Since in the Communication Manual it just mentions that the command needed to be send should be "STX-MEASURE()A-ETX". Is there any probability that I misundestood the manual ?

Download All
0 Kudos
Message 4 of 19
(7,459 Views)

Hi Dennis,

 

Thank you for your hint. I changed the "Display Style" in the "String Properties" of each strings to hexadecimal. Nothing changes, still error.

Is there anything I miss ?

0 Kudos
Message 5 of 19
(7,457 Views)

The way you are specifying the stop bits (parameter 4), is all wrong. A value of 1 is not supported. Get rid of those constants and conversions. Right click on the input and select 'Create>Constant'. The enum value for '1 stop bit' is 10. The context help also shows this so this an important lesson. Always have context help turned on and then pay attention to it.

0 Kudos
Message 6 of 19
(7,454 Views)

Hi Dennis,

 

It works when I change the stops bit as your recommandation. There is no ERROR at the VISA Write. Thank you very much.

 

I am so sorry for not choosing "Accept as solution" for my initial question although it has been solved. Since I still need to read the respone from my laser sensor via VISA Read, then make further processing.

 

Although it looks like that I can send the COMMAND to the sensor now, however there is nothing in the "String read" of the VISA Read. I will try to work with this by myself and if I need some more advices I hope that you still can help me out.

0 Kudos
Message 7 of 19
(7,446 Views)
Solution
Accepted by topic author NCHU

I have my LV code run successfully. It can read in the COMMAND and send back the measurement data. Last time there is no response from the VISA Read because I have used a second-hand RS232 cable, and someone has switched the two pins (2 and 3) for some other application.

0 Kudos
Message 8 of 19
(7,436 Views)

As always RS 232 means Regularly Soldering pin 2->3->2

greetings from the Netherlands
Message 9 of 19
(7,421 Views)

I apologize for raising other questions for my case even though my initial problem related to communication between my sensor and PC has been solved. Hope everybody still attends this thread and can give me help.

 

Attched is a VI that send a command "MEASURE START_A" --> continous reading out of measurement value of HEAD A.

 

I am dealing with these problems:

 

(1). I want to read the real time measurement data in a specified time sending out by the sensor after receiving the above command. However, in the VISA Read we usually set up "byte count" (the number of byte to be read). How can I set up this real time reading instead of byte count ?

 

(2). In order to stop the continous reading out, a command needs to be sent to the sensor (MEASURE STOP). In my attached VI, I also try to save the data into a Text file. However every time I run this VI, a part of previous measurement data is save to the current file. I guest, some how those data still exist some where else in the buffer or such when last run is stop. How can I refresh the VISA Read before each run to eliminate this problem?

 

(3). One more attention I want to make. In the communication manual pdf file, in the end lines of page 17, it writes "Even though the continous reading out stops after accepting the command other than the stop command, the response against it cannot be guaranteed" ???

 

Much much appreciate for your continous help for my problem.

Download All
0 Kudos
Message 10 of 19
(7,391 Views)