svanted skrev:kommer skräptecknen varje gång arduinon startas om eller när pc programmet startas om?
Uppstår alltid när terminalprogrammet omstartas (med högre överföringshastighet än 9600bps)
(både "mitt" och andra...)
svanted skrev:… hur initieras inputbufferten i autohotkey?
Kan det vara en felaktig eller obefintlig initiering?
Svårare att svara på.
Initieringen jag använder hittade jag på Autohotkeys forum. (och är skrivet för Windows XP.)
Bättre hade varit att hitta hur den seriella initieringen borde se ut mot Arduino.
Sedan anpassa detta mot Windows 7 / 10 (Men inget jag hittat.)
1) Förutsättningar sätts upp .:
COM3:baud=115200 parity=N data=8 stop=1 dtr=Off
2) Kommunikationen initieras på följande sätt (Autohtokey) - Endast initieringsfunktionen. (önskas hela programmet - inga problem!)
Kod: Markera allt
RS232_Initialize(RS232_Settings)
{ ; ###### Extract/Format the RS232 COM Port Number ######
; 7/23/08 Thanks krisky68 for finding/solving the bug in which RS232 COM Ports greater than 9 didn't work.
StringSplit, RS232_Temp, RS232_Settings, `:
RS232_Temp1_Len := StrLen(RS232_Temp1) ; For COM Ports > 9 \\.\ needs to prepended to the COM Port name.
If (RS232_Temp1_Len > 4) ; So the valid names are
RS232_COM = \\.\%RS232_Temp1% ; ... COM8 COM9 \\.\COM10 \\.\COM11 \\.\COM12 and so on...
else
RS232_COM = \\.\%RS232_Temp1%
; 8/10/09 A BIG Thanks to trenton_xavier for figuring out how to make COM Ports greater than 9 work for USB-Serial Dongles.
StringTrimLeft, RS232_Settings, RS232_Settings, RS232_Temp1_Len+1 ; Remove the COM number (+1 for the semicolon) for BuildCommDCB.
; MsgBox ,, Row %A_LineNumber% -> %A_ScriptName%, RS232_COM=%RS232_COM% `nRS232_Settings=%RS232_Settings%
;###### Build RS232 COM DCB ######
; Creates the structure that contains the RS232 COM Port number, baud rate,...
VarSetCapacity(DCB, 28)
BCD_Result := DllCall("BuildCommDCB"
,"str" , RS232_Settings ;lpDef
,"UInt", &DCB) ;lpDCB
If (BCD_Result <> 1)
{ ; MsgBox, There is a problem with Serial Port communication. `nFailed Dll BuildCommDCB, BCD_Result=%BCD_Result%.
; Exit
RS232_FileHandle:=0
Return %RS232_FileHandle%
}
; ###### Create RS232 COM File ######
; Creates the RS232 COM Port File Handle
RS232_FileHandle := DllCall("CreateFile"
,"Str" , RS232_COM ; File Name
,"UInt", 0xC0000000 ; Desired Access
,"UInt", 3 ; Safe Mode
,"UInt", 0 ; Security Attributes
,"UInt", 3 ; Creation Disposition
,"UInt", 0 ; Flags And Attributes
,"UInt", 0 ; Template File
,"Cdecl Int")
If (RS232_FileHandle < 1)
{ ; MsgBox, There is a problem with Serial Port communication. `nFailed Dll CreateFile, RS232_FileHandle=%RS232_FileHandle% `nThe Script Will Now Exit.
RS232_FileHandle:=0
Return %RS232_FileHandle%
}
; ###### Set COM State ######
; Sets the RS232 COM Port number, baud rate,...
SCS_Result := DllCall("SetCommState"
,"UInt", RS232_FileHandle ;File Handle
,"UInt", &DCB) ;Pointer to DCB structure
If (SCS_Result <> 1)
{ ; MsgBox, There is a problem with Serial Port communication. `nFailed Dll SetCommState, SCS_Result=%SCS_Result% `nThe Script Will Now Exit.
RS232_Close(RS232_FileHandle)
; Exit
}
; ###### Create the SetCommTimeouts Structure ######
ReadIntervalTimeout = 0xffffffff
ReadTotalTimeoutMultiplier = 0x00000000
ReadTotalTimeoutConstant = 0x00000000
WriteTotalTimeoutMultiplier= 0x00000000
WriteTotalTimeoutConstant = 0x00000000
VarSetCapacity(Data, 20, 0) ; 5 * sizeof(DWORD)
NumPut(ReadIntervalTimeout, Data, 0, "UInt")
NumPut(ReadTotalTimeoutMultiplier, Data, 4, "UInt")
NumPut(ReadTotalTimeoutConstant, Data, 8, "UInt")
NumPut(WriteTotalTimeoutMultiplier, Data, 12, "UInt")
NumPut(WriteTotalTimeoutConstant, Data, 16, "UInt")
; ###### Set the RS232 COM Timeouts ######
SCT_result := DllCall("SetCommTimeouts"
,"UInt", RS232_FileHandle ;File Handle
,"UInt", &Data) ;Pointer to the data structure
If (SCT_result <> 1)
{ ; MsgBox, There is a problem with Serial Port communication. `nFailed Dll SetCommState, SCT_result=%SCT_result% `nThe Script Will Now Exit.
RS232_Close(RS232_FileHandle)
; Exit
}
; Msgbox %RS232_FileHandle%
Return %RS232_FileHandle%
}
3a) Skicka en rubrik .:
header := "- - - TERMINAL OUTPUT - - -" . chr(10) . chr(10) . ">>"
Det som skickas ser ut på följande sätt .:
0x2D,0x20,0x2D,0x20,0x2D,0x20,0x54,0x45,0x52,0x4D,0x49,0x4E,0x41,0x4C,0x20,0x4F,0x55,0x54,0x50,0x55,0x54,0x20,0x2D,0x20,0x2D,0x20,0x2D,0xA,0xA,0x3E,0x3E,
Slasktecken och rubrik visas direkt. Har testat olika fördröjningar, men utan resultat.
(Avslutar med tom post - ska det vara så?
Ska tecknen skickas på ovanstående sätt? (eller ska de sickas som sträng 2D202D20 osv...)
Jag har ingen aning.....
3b)
Skriver sedan in 1 2 3 4 - tecken för tecken returneras (som förväntat) - ex. på resultat (och slask tecken) .:
SimpleTerm1.jpg
4kTRB skrev:Testa att addera en loop som väntar på Serial efter Serial.begin.
While(!Serial)
Gav följande program på Arduino UNO .:
Kod: Markera allt
void setup() {
Serial.begin(115200);
while (!Serial) {} // wait for serial port to connect. Needed for native USB port only - Ingen skillnad!
}
void loop(){
while (Serial.available() > 0) {
Serial.write(Serial.read());
}
}
Upplevde dock ingen skillnad...
Du har inte behörighet att öppna de filer som bifogats till detta inlägg.