COMポートでの通信ですか。最近やってみた感じなんかさっくり動きますよ。
http://www.salutesound.com/~oss_winapi232.html
C++の資料。
HSPで組む場合、構造体の情報なんかを引っ張ってくるのが大変なんですよ。
なお、以下テストをまともにしてないので動作は未保証。動かなかったら適当に直してねん。
#module MComPort PortHandle
#uselib "kernel32.dll"
#cfunc CreateFile "CreateFileA" str,int,int,sptr,int,int,sptr
#func GetCommState "GetCommState" int,sptr
#func SetCommState "SetCommState" int,sptr
#func ClearCommError "ClearCommError" int,sptr,sptr
#func ReadFile "ReadFile" int,sptr,int,sptr,sptr
#func CloseHandle "CloseHandle" int
#ifndef NULL
#const global NULL 0
#endif
#const GENERIC_READ 0x80000000
#const GENERIC_WRITE 0x40000000
#const OPEN_EXISTING 3
#const global NOPARITY 0 // パリティなし
#const global ODDPARITY 1 // 奇数パリティ
#const global EVENPARITY 2 // 偶数パリティ
#const global MARKPARITY 3 // Markパリティ
#const global SPACEPARITY 4 // スペースパリティ
#const global ONESTOPBIT 0
#const global ONE5STOPBITS 1
#const global TWOSTOPBITS 2
#modinit int comPortNumber
PortHandle = CreateFile(strf("\\\\.\\COM%d",comPortNumber),GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL )
return
#modcfunc MComPort_FailedInit
return PortHandle & 0x80000000
#modfunc MComPort_SetPortDCB int baudRate,int byteSize,int parity,int stopBits,local dcb
dim dcb,7 // sizeof(DCB) == 28
dcb.0 = 28 // DCBlength
GetCommState PortHandle,varptr(dcb)
lpoke dcb, 4,baudRate // BaudRate
poke dcb,18,byteSize // ByteSize
poke dcb,19,parity // Parity
poke dcb,20,stopBits // StopBits
SetCommState PortHandle,varptr(dcb)
return
#modfunc MComPort_SetEOFChar int eofChar,local dcb
dim dcb,7 // sizeof(DCB) == 28
dcb.0 = 28 // DCBlength
GetCommState PortHandle,varptr(dcb)
poke dcb,24,eofChar // EOFChar
SetCommState PortHandle,varptr(dcb)
return
#modfunc MComPort_RecvData var dataMemory,int recvSize,local recvedSize
dim recvedSize
ReadFile PortHandle,varptr(dataMemory),recvSize,varptr(recvedSize),NULL
return recvedSize
#modcfunc MComPort_RecvedEofChar local dwer,local comstat
dim comstat,3 // sizeof(COMSTAT) == 12
dim dwer,1
ClearCommError PortHandle,varptr(dwer),varptr(comstat)
return ( comstat.0 & ( 1<<5 ) ) != 0
#modcfunc MComPort_RecvedSize local dwer,local comstat
dim comstat,3 // sizeof(COMSTAT) == 12
dim dwer,1
ClearCommError PortHandle,varptr(dwer),varptr(comstat)
return comstat.1
#modterm
CloseHandle(PortHandle)
return
#global
mes "START"
dimtype com1,vartype("struct")
newmod com1,MComPort,1
if MComPort_FailedInit(com1) {
mes "failed port open."
stop
}
mes "opened com port."
MComPort_SetPortDCB com1,9600,7,EVENPARITY,ONESTOPBIT
mes "set 9600bps - 7bit evenParity 1stopBit ."
repeat 100
recvsize = MComPort_RecvedSize(com1)
if ( recvsize > 0 ){
sdim mem,recvsize
MComPort_RecvData mem,recvsize
recvedsize = stat
mes "Recved "+recvedsize+" Byte ::["+mem+"]"
}
wait 1
loop
delmod com1
mes "END"
とりあえずCOMポートでの通信(受信)ができれば何とかなるんじゃないかね?