How do I send hex command as mmcorej.CharVector to serial port?
Afficher commentaires plus anciens
Hi All,
I am trying to send a hex message to a light source connected by a usb through the virtual serial port. The source expects an up to 8 byte message, for example 'A9035301A95C' in order to change state. I am trying to communicate with it via Micro Manager adapter for Free Serial Port. Micro Manager command has the following format: setSerialPortCommand(String portLabel, String command, String term) where String command is java.lang.String command.
I tried various forms of the code below, but with no success. I would greatly appreciate any advice on the correct format for the command.
cheers, Maria
function [] = setBrightFieldManual(color,intensity)
global mmc;
comPortScopeLED = 'COM5';
presetColors = {'3000K','4500K','6500K','Red ','Green','Blue '}; % from manual
colorNumbers = {'01','02','03','04','05','06'};
colorMap = containers.Map(presetColors,colorNumbers);
intensityHEX = dec2hex(intensity);
checkSum = dec2hex(2^8-(81+hex2dec(colorMap(color))+intensity));
playPresetColorString = {'A9','04','4D',colorMap(color),intensityHEX,checkSum,'5C'};
setManualControllerLockoutON = {'A9','03','53','01','A9','5C'};
setUSBControl = {'A9','03','27','03','D3','5C'};
setManualControllerLockoutOFF = {'A9','03','53','00','AA','5C'};
getManualControllerLockout = {'A9','02','54','AA','5C'};
setAllShuttersOpen = {'A9','03','55','07','A1','5C'};
mmc.setSerialPortCommand(comPortScopeLED,'A9035301A95C',''); % also tried (comPortScopeLED,'setManualControllerLockoutON','')
mmc.setSerialPortCommand(comPortScopeLED,'A90254AA5C','');
answer=char(mmc.readFromSerialPort(comPortScopeLED));
disp(answer);
mmc.setSerialPortCommand(comPortScopeLED,'setUSBControl','');
mmc.setSerialPortCommand(comPortScopeLED,'setAllShuttersOpen','');
mmc.setSerialPortCommand(comPortScopeLED,'setManualControllerLockoutOFF','');
Réponses (2)
Walter Roberson
le 11 Août 2017
h2js = @(hexstring) java.lang.string( char(sscanf(hexstring, '%02x')) )
mmc.setSerialPortCommand(comPortScopeLED, h2js('A9035301A95C'), '');
That is, you need to convert the hex to bytes, and the bytes to java string.
1 commentaire
Maria M.
le 16 Août 2017
Catégories
En savoir plus sur Startup and Shutdown dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!