Post by johnk1ese on Aug 23, 2020 3:46:05 GMT -5
I am trying to write a program to poll a commercial inverter once every two seconds.
The inverter manual says -
● RS232 communication port controls with non-synchronous serial transmission (ASCII cord) method.
● RS232 communication program is real time operation, and status can be monitored through serial function of PC screen by program
connected with and provided by computer (PC) application port.
● When using RS232 communication programs other than ones provided by our company, data in each mode can be verified using following
command through PC connection.
Input voltage indication command: BAT?
Output voltage indication command: VOL?
Frequency indication command: FRQ?
Output current indication command: AMP?
When entering commands in the command window, even question marks should be typed accurately, and make sure to use upper case as it
distinguishes upper and lower cases.
I wrote this code -
I had tried it without opening and closing the port each time but it would get extra characters left over from the prior message instead of just the message response from the new command. I couldn't flush the buffer each time and closing the port was the only thing that worked.
However, with the code above it works a few cycles before there is a serial port error and the program crashes. I don't know what to try next
John K1ESE
The inverter manual says -
● RS232 communication port controls with non-synchronous serial transmission (ASCII cord) method.
● RS232 communication program is real time operation, and status can be monitored through serial function of PC screen by program
connected with and provided by computer (PC) application port.
● When using RS232 communication programs other than ones provided by our company, data in each mode can be verified using following
command through PC connection.
Input voltage indication command: BAT?
Output voltage indication command: VOL?
Frequency indication command: FRQ?
Output current indication command: AMP?
When entering commands in the command window, even question marks should be typed accurately, and make sure to use upper case as it
distinguishes upper and lower cases.
I wrote this code -
[setup.main.Window]
'-----Begin code for #main
nomainwin
WindowWidth = 250
WindowHeight = 200
UpperLeftX=100
UpperLeftY=100
BackgroundColor$ = "Yellow"
ForegroundColor$ = "black"
'-----Begin GUI objects code
statictext #main.dc,"DC Input", 5, 5, 100, 25
statictext #main.ac,"AC Output", 5, 35, 100, 25
statictext #main.fr, "Frequency", 5, 65, 100, 25
statictext #main.am, "AMP", 5, 95, 100, 25
statictext #main.dcshow, "DC", 120, 5, 90, 25
statictext #main.acshow, "AC", 120, 35, 90, 25
statictext #main.frqshow, "Freq", 120, 65, 90, 25
statictext #main.ampshow, "Amp", 120, 95, 90, 25
button #main.buttonstart, "Start", [startClick], UL, 5, 130, 100, 25
button #main.buttonstop, "Stop", [stopClick], UL, 120, 130, 100, 25
'-----End GUI objects code
open "C:\AIMS\AIMS Monitor.ini" for window as #main
print #main, "font ms_sans_serif 14"
#main "trapclose [close]"
Com = 16384
[configure]
oncomerror [badport]
inverterport$ = "com3:2400,n,8,1"
wait
[startClick]
timer 2000, [reading]
[reading]
open inverterport$ for random as #aims
buffer$ = ""
dataRead$ = ""
print #aims, "BAT?"
while len(buffer$) < 4
dataRead$=input$(#aims, 1)
buffer$=buffer$+dataRead$
scan
wend
print #main.dcshow, Left$(buffer$,4)
dataRead$ = ""
close #aims
open inverterport$ for random as #aims
buffer$ = ""
dataRead$ = ""
print #aims, "VOL?"
while len(buffer$) < 4
dataRead$=input$(#aims, 1)
buffer$=buffer$+dataRead$
scan
wend
print #main.acshow, Left$(buffer$,4)
buffer$ = ""
close #aims
open inverterport$ for random as #aims
buffer$ = ""
dataRead$ = ""
print #aims, "FRQ?"
while len(buffer$) < 4
dataRead$=input$(#aims, 1)
buffer$=buffer$+dataRead$
scan
wend
print #main.frqshow, Left$(buffer$,4)
buffer$ = ""
close #aims
open inverterport$ for random as #aims
buffer$ = ""
dataRead$ = ""
print #aims, "AMP?"
while len(buffer$) < 4
dataRead$=input$(#aims, 1)
buffer$=buffer$+dataRead$
scan
wend
print #main.ampshow, Left$(buffer$,4)
buffer$ = ""
close #aims
wait
[stopClick]
goto [close]
[badport]
notice, "Serial Port Error"
notice, "Error: "; ComError$
notice, "Port number: "; ComPortNumber
notice, "Error code: ";ComErrorNumber
close #aims
[close]
close #main
end
I had tried it without opening and closing the port each time but it would get extra characters left over from the prior message instead of just the message response from the new command. I couldn't flush the buffer each time and closing the port was the only thing that worked.
However, with the code above it works a few cycles before there is a serial port error and the program crashes. I don't know what to try next
John K1ESE