"Enter" Key in Serial Communication with External Device

14 views (last 30 days)
I am using a Matlab script to establish serial communication with an Amber Electrical Conductivity Meter (ECM) model 3084. I am able to connect with the device, and when I send the character “C” (i.e. the capital letter only) to the device using Matlab’s fprintf function, the ECM sends back to the Matlab command window (using the fscanf function) all initialization information for the device (i.e. temperature set-point, baseline conductivity, and other parameters). However, I would like to send the appropriate command to the ECM, so that it responds by sending real-time conductivity data to the Matlab command window. Unfortunately, the ECM does not have any serial command documentation, and I found that a “C” sends all device initialization information just by trial and error (i.e. trying lots of buttons on the keyboard).
My glimmer of hope: I am also able to establish serial communication with the device via the terminal emulator PuTTY. When I send the ECM a “C” alone via the PuTTY terminal window, the device logically sends back all initialization information. However, when I simply push the “enter” or “return” key in the PuTTY terminal window, the ECM responds by sending a real-time conductivity measurement! I have tried every conceivable combination of characters to represent an “enter” or “return” via Matlab’s fprintf function (i.e. “CR”,<cr>,”CR/LF”,”\r\n”,’\n”, and many variations thereof), but nothing yields a conductivity measurement like when I communicate with the ECM using PuTTY. An interesting observation is that whenever I send the ECM a command that starts with a “C”, even if it’s a single character in a longer command (e.g. “CR”), the ECM responds by sending just the initialization info. In other words, the ECM seems to only interpret the first character in every command.
Does anyone have any ideas for how I might be able to send the ECM the appropriate Matlab-based signal/character/series of characters to initiate a real-time data response? While not necessarily pertinent to this site, another question might be: what exactly does PuTTY send when one pushes the “enter” or “return” key in a serial session, and how can it be represented in a Matlab fprintf function?
Sorry for the long post. Thank you for your time. See my script below.
Sam
%Match serial comm. parameters of ECM; note terminator is line feed, %then carriage return (a combo that does not exist in ECM output, %so entire file is read)
%make certain to specific correct COM port... %the terminator is a symbol that is not in output so that all data is %flushed after timout... s = serial('COM8','BaudRate',9600,'DataBits',8,'Parity','none','StopBits',2,... 'FlowControl','none','Terminator','\','Timeout',0.5); fopen(s); fprintf(s,'C'); %send device command for data... output = fscanf(s) %scan for device response...
fclose(s); delete(s); %must delete serial object after each trans. to free comm. line

Answers (1)

Markus
Markus on 3 Jan 2019
Edited: Markus on 3 Jan 2019
Try this command
fwrite(s,13,'char');
13 (decimal) representes the 'carriage return' in the ASCII table.

Categories

Find more on Instrument Control Toolbox Supported Hardware 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!

Translated by