Instrument Control (GPIB, Serial, VISA, IVI)

cancel
Showing results for 
Search instead for 
Did you mean: 

controlling a power supply through serial (USB)

Hey Everyone,
 
I just posted this on the wrong part of the forum (Thanks KC for pointing it out) Anyways, I am pretty new to LabView, and am trying to use LabView to control a High Voltage (HV) power supply through the USB port. The driver for it is installed and it is emulating COM3 port, which LabView can see. I am just trying to test the commanding by using the Basic Serial Write and Read.vi from the tutorial.
 
The power supply that i'm using states the following in the manual:
Serial communications will use the following protocol:
<STX><CMD><,>ARG><,><CSUM><ETX>
Where:
<STX> = 1 ASCII 0x02 Start of Text character
<CMD> = 2 ASCII characters representing the command ID
<,> = 1 ASCII 0x2C character
<ARG> = Command Argument
<,> = 1 ASCII 0x2C character
<CSUM> = Checksum (see section 6.3 for details)
<ETX> = 1 ASCII 0x03 End of Text character
 

6.3 CHECKSUMS

The checksum is computed as follows:

Add the <CMD>, <,>, and <ARG> bytes into a 16 bit (or larger) word.
The bytes are added as unsigned integers.
Take the 1’s compliment (negate it).
Truncate the result down to the eight least significant bits.
Clear the most significant bit (bit 7) of the resultant byte, (bitwise AND with 0x7F).
Set the next most significant bit (bit 6) of the resultant byte (bitwise OR with 0x40).
Using this method, the checksum is always a number between 0x40 and 0x7F.
The checksum can never be confused with the <STX> or <ETX> control
characters, since these have non-overlapping ASCII values.

so this means if i try to use command #14 for example, with argument 100, then i would write

<STX>14,100,<CSUM><ETX> (this is shown in an example of the manual)

adding 14, 44(ascii comma), 100 together = 158, so 10011110, then complement it i get 01100001

if i clear the most significant bit, i assume that means delete it?: 1100001
then set the most significant remaining bit, that means make it a 1? so i get 1100001 (dec:97 hex:61)

now to translate this to the string that labview wants, do i enter
\214\2C100\2C\61\3                 ?
 
when i run that line into the sample program, i get the following error:

http://img215.imageshack.us/img215/5486/visaerrormz3.jpg

This error is different if i unplug the power supply, so that means that the LabView is at least seeing the powersupply on COM3, which is good. but what i did above definately doesnt work

if anyone has experience with this or recognizes the command structure i would appreciate any help
thanks in advance!
0 Kudos
Message 1 of 10
(5,504 Views)

Have you searched the Instrument Driver Network to see if a driver exists for the supply? If there isn't one, you should provide the make and model of what you are using.

What you are attempting to do is fairly common. One particular thread sticks in my head becuase of the large number of posts. There were several code examples posted there on formatting to hex and how calculate a checksum. You should also post any code you've written so people can examine it for errors.

0 Kudos
Message 2 of 10
(5,497 Views)
Unfortunately the driver network didn't have anything for my device. The power supply is a Spellman SL150, and i have the USB driver installed, so all i have to do is feed a string to the COM port (and i have set the COM port settings set i believe)
 
i'm just wondering if the syntax i'm using (that the power supply manual gave) is correct (i'm pretty sure its not) if i'm feeding it in as a string.
 
the manual for the power supply is attached but i think i copy/pasted the important stuff in my message:
 
thanks again! I will go read through that thread you gave me a link to.


Message Edited by estomax on 04-25-2008 11:37 AM
0 Kudos
Message 3 of 10
(5,495 Views)
I can't tell if the syntax you are sending is correct since you did not post the actual program. Because there are different ways to represent strings in LabVIEW, it's important to see what you've done. For example, if you want to send hex, you can right click on the string control/constant and select Hex display. I think you will find a lot of help in some of example programs in the other thread. The commands are different but the basic technique is the same.

Message Edited by Dennis Knutson on 04-25-2008 10:41 AM
0 Kudos
Message 4 of 10
(5,492 Views)
Hey Dennis,
 
thanks for the relpy, the program i am using is just the sample "Basic serial write and read.vi" from the labView tutorials. It has COM settings on the left side and then a write window and a read menu on the right side. I put the string i created above and put it into the write bar and tried to run the vi, and it gave me the error. I don't have access to the labview computer at the moment but i will try to get more information about what i'm doing 🙂
 
thanks
0 Kudos
Message 5 of 10
(5,483 Views)

I didn't look at the error before because I really don't want to view something that is hosted elsewhere. I'ts better to just attach something to your post (use the Browse button next to the attachment filed below the message body). I guess I was assuming that you had a read error as write errors are not nearly as common.

I have seen that error reported with certain USB-RS232 adapters. See if this helps.

0 Kudos
Message 6 of 10
(5,470 Views)
so I am still not sure how LabView takes in strings of ascii characters. When i feed it a string with following format:
 
<STX><CMD><,>ARG><,><CSUM><ETX>
Where:
<STX> = 1 ASCII 0x02 Start of Text character
<CMD> = 2 ASCII characters representing the command ID
<,> = 1 ASCII 0x2C character
<ARG> = Command Argument
<,> = 1 ASCII 0x2C character
<CSUM> = Checksum (see section 6.3 for details)
<ETX> = 1 ASCII 0x03 End of Text character
 
then say i have command 12 (0x310x32 ?), argument 1000 and resulting checksum 1F
 
can i type in labview's string field to send to command port:
0x020x310x320x2C0x310x300x300x300x2C0x1F0x03     ?????? is this the correct notation for above given format?
 
thanks for any input
Marko
0 Kudos
Message 7 of 10
(5,409 Views)

No, you don't format the string in that manner. In LabVIEW, you have several options. One is to use a string control/constant set to hex display. You right click on the control/constant and select this option. Then you would just enter the values you hvae without the '0x'. another way is to create an array of U8 values. Then the Byte Array to String function can be used. In your case, assuming that you will be selecting different commands and needing to calculate the CRC, this would probably work the best as you can some fixed array values and use the build array function with the values you provide and calculate. In that long post I provided a link to, there was an example of that.

 



Message Edited by Dennis Knutson on 05-02-2008 07:12 AM
0 Kudos
Message 8 of 10
(5,392 Views)
hey Dennis,
 
thanks for the reply. i found the byte to string button, but where do i find that U8 / hex display thing where i can enter hex digits to send into the com port. ?
 
i am somewhat of a noobie at this LabVIEW stuff, so bear with me 🙂
 
cheers
Marko
0 Kudos
Message 9 of 10
(5,338 Views)

That's an array constant. On the array palette, select Array Constant. On the numeric palette, select Numeric Palette and drop that into the array constant. Right click on the numeric and select Representation>U8. Right click again on the numeric palette and select Display Format. Select hex. Right click on the numeric constant again and select Visible Items>Radix.

You are going to have to master some of the basics of LabVIEW to get your program to work. I would recomend starting here.

 

0 Kudos
Message 10 of 10
(5,335 Views)