LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Write to Serial Port without splitting string data

Hi, all, thank you for your help in advance.
 
Problem:
I am trying to write to the serial port with VISA write module. Somehow the string I tried to send was splitted before it was sent. For example, if I want to send "127", it sends "7', "2", "1". I don't know if there's anyway to configure the module so that it sends out the whole string at once. I use the return count to indicate how many times it spits the data. So "127" now returns "3" (sent three times. I would like to have it to return "1" so that "127" was sent in whole).
 
Project:
I am working on an application where a DC motor is controlled by a controller talking to the PC's serial port. "127" stands for its maximum power. The controller devides the power into 128 steps. Therefore I need to input number from 0 to 127 to command the speed.
 
Any help or suggestion will be appreciated!
0 Kudos
Message 1 of 14
(4,157 Views)
Please post your code so we can see if there is anything wrong there.  Serial ports always send data 1 byte at a time, but if you write a string with 3 bytes, they will go out one right after the other without any delay.  And I've never heard of it sending it in reverse order, so it must be something with your code.
0 Kudos
Message 2 of 14
(4,151 Views)
Hello Winup,
the return count indicates the number of bytes sent to the serial port, so if you are sending a given string, you should expect return count=string length, e.g. 3 for "127" (as you actually see). Furthermore, the sending order is the opposite of what you suggested: for "127", the actual order is "1","2","7". This does not mean necessarily that the receiver will get the input as three separate inputs: the three bytes are sent with a nearly null intercharacter delay.
Paolo
-------------------
LV 7.1, 2011, 2017, 2019, 2021
0 Kudos
Message 3 of 14
(4,150 Views)
If you connect the whole string "127", than the VI VISA Write should send all together without or with very small time distance between chars.
Compare the interface settings on your side and on the device side. Look the timeout value between chars (Intercharacter Time) on the device side, if it is setable, than try to make it higher.


Message Edited by Eugen Graf on 02-29-2008 10:28 AM
0 Kudos
Message 4 of 14
(4,149 Views)
If i understand correctly :
You want to sent the number 127. But you send the string "127" which is completely different.
String "127" constist from 3 bytes: 49, 50 , 55. This is the ASCII code.
If you want to send the number 127, write a number, convert it to string and send it to port. this is only one byte.
0 Kudos
Message 5 of 14
(4,143 Views)
Ouao. So many answers in so little time....
I think he has just comfused the ASCII and RTU codes
0 Kudos
Message 6 of 14
(4,137 Views)

Thanks for the prompt replies.

About Number/ASCII

I am using the Atmega128-Controller Chip to read in the signals sent from the computer serial port. Then it sends signals to the motor controller. The Atmega chip reads the ASCII string and converts it to hexadecimal number, sending that number to the motor controller. I can program the Atmega chip so that it either translates the ASCII string into hex as mentioned or accepts as it is. Either way, I want it to read two byte information at once (00 to 7F).

If the VISA serial write can send only one byte at a time, then I may have to program the chip so that it buffers the readings. I have tried using number/hex converter and number/string converter, either case, the fact that VISA Write spits one byte at a time hinders the programming. For example: I defined numbers 1 to 5 represents 20% to 100% power output with 20% increment Then I defined "10" as "90%" power, but it reads "1" "0" seperately, so the actual out put is "20%" then "0%".

I used the example VI provided by NI : advanced serial write/read. For convenience, attached here. Not all modification I made is saved.

0 Kudos
Message 7 of 14
(4,123 Views)
0 Kudos
Message 8 of 14
(4,119 Views)

Some of the things you are saying is contradictory. 00 to 7F is not two bytes, it is one byte.

All serial transmission is done one byte at a time, not just in LabVIEW.

Number/hex and Number/string conversion is not correct. If you want to send hex, the simplest way is to right click on your string contro/constant and select Hex Display. Now you can enter in a single byte (00 to 7F). You can also use a numeric control/constant and the Byte to String Array or just the Type Cast function.

0 Kudos
Message 9 of 14
(4,118 Views)

Atmega128 also reads one byte at the time. And when the receiving info, is more than one byte, you always have to buffer it (in the mega128).

VISA works the the same way.

Raw numbers are easier to use, than ASCII. If you use ASCII the mega128 should decode the incomming data.

0 Kudos
Message 10 of 14
(4,084 Views)