LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Communication with Neuromuscular Stimulator via Serial Port

How's it going everyone, I just began using labview about 2 weeks ago and I've been thrown in a loop trying to control a Hasomed RehaStim neuromuscular stimulator in science mode. For my purpose I just want to prompt the device to send a single pulse base on the input parameters (numeric controls on the frontview). I was using Coolterm as a pilot test with the device to ensure it was working and found that it worked best when sending Hex strings, so I wrote a MATLab function that generates the hex string based on the inputs. I want to send this string to the device using a push button but it does not seem to be working in the way I want. Any help would be great!

 

P.S. two Matlab functions needed:

function [hexcs]=ChecksumM32(Chan,Width,Amp)
Sum=Chan+Width+Amp;
Binsum=dec2binvec(Sum);
LSB5= Binsum(1:5);
bincs=[0 0 0 0 0 1 1 1];
bincs(1:5)=LSB5;
cs=flip(bincs);
hexcs=binaryVectorToHex(cs);
end
function [puslehex] = Pulsehexgen(Chan,Width,Amp) %Generate the Hex String to generate pulse for NMES, Inputs of Channel Numbers (0-7), Pulse Width in uS, and Current Amplitude in mA
hexcs=ChecksumM32(Chan,Width,Amp);
BinChan=dec2binvec(Chan,3);
BinW=dec2binvec(Width,9);
BinA=dec2binvec(Amp,7);
rB1=[0 0 0 0 0 0 0 0]; rB2=[0 0 0 0 0 0 0 0]; rB3=[0 0 0 0 0 0 0 0];
rB1(5:7)=BinChan; rB1(1:2)=BinW(8:9);
rB2(1:7)=BinW(1:7);
rB3(1:7)=BinA;
B1=flip(rB1); B2=flip(rB2); B3=flip(rB3);
B1hex=binaryVectorToHex(B1);
B2hex=binaryVectorToHex(B2);
B3hex=binaryVectorToHex(B3);
puslehex=[hexcs,B1hex,B2hex,B3hex];
end
0 Kudos
Message 1 of 10
(2,012 Views)

Hi JM,

 


@JMartinez217 wrote:

For my purpose I just want to prompt the device to send a single pulse base on the input parameters (numeric controls on the frontview). I was using Coolterm as a pilot test with the device to ensure it was working and found that it worked best when sending Hex strings, so I wrote a MATLab function that generates the hex string based on the inputs. I want to send this string to the device using a push button but it does not seem to be working in the way I want. Any help would be great!


Several problems:

  • Your attachment is created using the latest version of LabVIEW (2022Q3), but very few of the seasoned LabVIEW users actually use this version (due to licensing problems). When you want help you should attach a down-converted version of the VI (File->Save for previous)!
  • Why do you involve Matlab when you want to create a LabVIEW VI? LabVIEW can create "hex strings" quite easily…
  • Have you watched this video yet?
Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 2 of 10
(1,957 Views)

1. Thanks for the insight, I take that into consideration the next time I upload. 

2. The reason I used MATLab was because I ran into a lot of issues with number conversion from floats to U8 and so forth. There was also indexing need to generate the hexcode that I need. for example the system has a 4 Byte sequence that Byte 0-3 

byte 0 is the indent 1 1 1 followed by the 5 LSB from the the summations of the inputs. 

So for the other Bytes there are specific bits required from the inputs and in the end when I would convert the Hexcode but it would be completely wrong. So I decided it would be easier with MATLab

3.I have seen this video, but I'll rewatch it again and see if I come to a breakthrough

0 Kudos
Message 3 of 10
(1,895 Views)

I tried the VI from the video as well as made more of my own and the error message I receive is "VISA: (Hex 0xBFFF001E) The specified state of the attribute is not valid, or is not supported as defined by the resource." When I looked through the forum it seems like there have been other users in the past that have had issues communicating with devices with baud rate setting of 115200 like mine. I'm not really to sure how this can be fixed. 

0 Kudos
Message 4 of 10
(1,827 Views)

I am going to help you with useful information:

 

Try to know a little more about the device. Do you know what communication protocol does it use?

 

See if the device can be shown on NIMAX under device interfaces. 

If not, find out if your device has a software of its own for hardware configuration. If it does, follow the instruction for device configuration. 

See if the device uses HiSLIP (high speed lan instrument protocol). If it does, make sure it's enabled. 

Once you are done with device configuration using the software that comes with your device, go to NIMAX and add your device. 

If the device is added, you can see its address on NIMAX. If you can see it on NIMAX, you should be good to go using VISA. 

Try to see if your device needs to use commands to be able to read data from it. These commands can be used on your block diagram to get some response from the device. 

Also make sure, you download all the drivers needed for your device to function properly.

You can also create your own instrument driver for communication with labview. But this may take times. You will need to know more about your device.

Here is the link if you are interested: https://www.ni.com/en/support/downloads/instrument-drivers/tools-resources/developing-labview-plug-a...

 

Finally, don't forget to select my answer as the best. 

Message 5 of 10
(1,808 Views)

Thank you for your response, for the most part I already did all of the things you spoke of but I was able to trouble shoot more using NI Max. my Device needs to receive hex data, I believe I'm back on the right track now

0 Kudos
Message 6 of 10
(1,788 Views)

Sounds good! Good job! Let me know if you need further help.

Message 7 of 10
(1,780 Views)

So I made this text VI to write the hex code string that worked in the test panel to the device and it is not working. the string I want to send in hex is "F641480A", so in the test panel I wrote it as \F6\41\48\0A and this gave me my expected response of a stimulation pulse. When I send the same string  \F6\41\48\0A in the view there is no response or error that occurs. The test panel seems to do a conversion of some sort and sends \F6AH\n, so I attempted to send this in the VI as well and still nothing. Did I code the VI incorrectly?

0 Kudos
Message 8 of 10
(1,773 Views)

Try the attached code I created and let me know if it works. If it doesn't, don't worry. We  will work together until we find the solution. 

 

~Your homework is my homework ~ haha

 

Quick advice based on your shared code: Whatever you place outside of the while loop will only execute once.  So if you know you will be entering number or pressing a button regularly while you are running your test, make sure you put the control/input(s) in the loop. 

The loop (while loop) is like God. Without God or outside of God's plan is death, there is no life. Whatever you put outside of loop, can only execute once. So while loop brings life to the controls (buttons, and whatever input you use for control). Same here,  we need God, Jesus for eternal life. Outside of God, Jesus, it's eternal death in the lake of fire. 

This is an analogy to show how true knowledge and wisdom can only come from God through Jesus-Christ.

So remember this.

Hahaha

 

P.S: Do you know how many bytes you have to read? I have 1024. You can change it.

 

Okay, so try the code I have and let us know what you have.

Message 9 of 10
(1,761 Views)

Thanks for the pointers, but it still did not work. I have gotten it working, I changed the display setting of the string to hex display and that has seemingly fixed the issue. Thank you for all the help I greatly appreciated it.

0 Kudos
Message 10 of 10
(1,703 Views)