How to communicate with a torque cell through Matlab?

1 view (last 30 days)
Hi,
I'm trying to communicate with a torque cell using Matlab. Here is my code:
ser1 = serial('COM4', 'BaudRate', 9600);
fopen(ser1);
serialbreak(ser1);
fscanf(ser1);
while counter<=10
fprintf(ser1,'%s', 'Get_Offset_Value');
OffsetValue= fscanf(ser1);
fprintf(ser1,'%s', 'Get_Offset_Load');
OffsetLoad= fscanf(ser1);
fprintf(ser1,'%s', 'Get_Fullscale_Value');
FullscaleValue= fscanf(ser1);
fprintf(ser1,'%s', 'Get_Fullscale_Load');
FullscaleLoad = fscanf(ser1);
fprintf(ser1,'%s', 'Normal_Data_Request');
NormalDataRequest= fscanf(ser1);
fprintf(ser1,'%s', 'Get_Decimal_Point');
DecimalPoint= fscanf(ser1);
RawTorque = (NormalDataRequest-OffsetValue)*((FullscaleLoad-OffsetLoad)/(FullscaleValue-OffsetValue))/DecimalPoint;
Torque(counter) = RawTorque*141.6116;
end
fclose(ser1);
Get_Offset_Value, Get_Offset_Load, Get_Fullscale_Value, Get_Fullscale_Load, Normal_Data_Request, and Get_Decimal_Point are all commands that the Torque cell programming guide (link found below) has in it. http://www.futek.com/files/pdf/Manuals_and_Technical_Documents/USB1XX%20USB2XX%20Programmer's%20Guide.pdf
Basically, I'm trying to acquire these values. I have successfully created the connection with the torque cell through the serial port but I am having trouble acquiring the values after that. I am trying to do so by writing to the torque cell using fprintf and then scanning the torque cell using fscanf. When I do this though it comes up with an error stating "Warning: A timeout occurred before the Terminator was reached." I have tried changing the timeout to a longer period of time but the error still occurs. I usually get 'G Nª' along with the error and I don't know what that means. If I add more than one fscanf in a row, it gives me different values (usually just 0) with different units, but this is regardless of what I enter in the fprintf section.
Any suggestions on how to get actual values instead of this error?
Thanks,
Amy

Answers (0)

Categories

Find more on Test and Measurement in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!