The Boost.IO Manager application must be installed on your computer for the code below to work. This is because a COM port will be assigned to the ED device when it is installed in the Boost.IO Manager. When the ED device is installed as a COM port on your computer, it will not always install as COM3. Therefore you may need to edit the COM port value in the code below so that it uses the COM port for your ED device.

This code sends the "@01" command to an ED device to query the state of the IO lines. The ED device should then respond with the current status of its IO lines e.g. ">050A".

Example code:

clc; close all;

s = serial('COM3'); % connect to com3
set(s,'BaudRate',9600); % set the baudrate 9600, this is the default baud rate for ED devices
set(s,'Terminator','CR'); % specifies terminator for the serial port object

fopen(s); % open the com port

fprintf(s,'@01'); % send command @01
response = fscanf(s); % read the response from the ED device and assign to response variable
%out = instrfind % can uncomment this to see serial port object info

fprintf('Response: ')
disp(response) % displays the response of the query

fclose(s); % clean up the connection after finishing with it
delete(s);
clear s

 

Understand the Response

Discarding the ">"  from the response variable, the remaing characters are the hexadecimal response. The hex represents the IO Lines, for example with an ED-204, the top 2 characters represent the outputs and the bottom 2 characters represent the inputs.

If you convert the string 05 into binary, then you can see that each bit represents an IO Line:

	DOUT0 = 1 (closed)
	DOUT1 = 0 (open)
	DOUT2 = 1 (closed)
	DOUT3 = 0 (open)	

 

This bit of code shows how to extract a substring and convert it from a hexadecimal value to a numeric value. In this case, the second and third characters are extracted and then converted from their hexidecimal values to numeric values. The second part of the code applies the same process, but instead extracts the fourth and fifth integers.

	>> response % echo response to command line
		response = '<0510'

	>> hex2dec(response(2:3)) % convert the 2nd and 3rd characters from hex to decimal
		ans = 5

	>> hex2dec(response(4:5)) % convert the 4th and 5th characters from hex to decimal
		ans = 16

 

For more on the ASCII protocol see here.