Here’s what I’ve come up with, see below. This appears to work. Would you need a similar delay and retry anywhere there was a poll/response between the external and Opto22 controller? For example, in the bolded lines of the code listed below.
Why wouldn’t handshaking be part of the OptoScript commands?
Dale
/////////////////////////////////////////////////////// Code Starts Here ////////////////////////////////////////////////////////
// Initialize variables
sReturnString = “SubUndef”;
nReturnStatus = -99;
nSubCharCount = 0;
nRecBuffFlag = 1;
sResponse = “SubUndef”;
//Open a communcation handle
sComString = “tcp:” + slIPAddress + “:50001”; //Construct the connection string
SetCommunicationHandleValue(sComString, chSpellmaneSL); //Comm handle for Spellman eSL power supply
nStatus = OpenOutgoingCommunication(chSpellmaneSL); //Open an outing communcation channel
//Build string and send it
sSendString = chr(2) + slCode + “,” + chr(3); // Build a string to transmit
nStatus = TransmitString(sSendString, chSpellmaneSL); //transmit the Spellman command string
//Setup a timer
SetDownTimerPreset(1.0,SpellmanTimeout); //Set the spellman time
StartTimer(SpellmanTimeout); //Start the timeout timer
//Wait for characters in the buffer or timeout
while (nRecBuffFlag == 1)
nSubCharCount = GetNumCharsWaiting(chSpellmaneSL); //Get number of characters in buffer
if (nSubCharCount == 0) then
if (HasTimerExpired(SpellmanTimeout)) then
nRecBuffFlag = 0; //Set flag to stop trying to receive buffer
nStringReturnStatus = -1; //set subroutine as a failed return status
else
DelayMsec(10); //Wait for 2 spellman scan cycles
nRecBuffFlag = 1; //Set flag to continue to receive the buffer
endif
else
nRecBuffFlag = 0; //Set flag to stop trying to receive buffer
nStringReturnStatus = 0; //set subroutine as sucess return status
endif
wend
//Get the characters waiting and close socket
nStringReturnStatus = ReceiveNChars(sReturnString, nSubCharCount, chSpellmaneSL);
nStatus = CloseCommunication(chSpellmaneSL); //Close the spellman network socket
//Clip first and last character of return string
nEndPos = nSubCharCount - 2; //Find last character in string
GetSubstring(sReturnString, 1, nEndPos, sResponse);
// Return the Spellman return string
sSpellReturnString = sResponse;
nReturnStatus = nStringReturnStatus;
/////////////////////////////////////////////////////// Code Ends Here ////////////////////////////////////////////////////////