?? avr309.dpr
字號:
if SendToDriver(FNCNumberDoSetOutDataPort,Param1,Param2,OutputData,OutLength) then
Result:=NO_ERROR;
SetEvent(SerializationEvent);
end;
//-------------------------------------------------------------------------------------------------------
function DoSetOutDataPort(DataOutByte:byte):integer; stdcall export;
//;set data bits (if are bits as input, then set theirs pull-ups)
begin
Result:=DoSetOutDataPorts(DataOutByte,DataOutByte,DataOutByte,$FF);
end;
//-------------------------------------------------------------------------------------------------------
function DoGetOutDataPorts(var DataOutByteB, DataOutByteC, DataOutByteD:byte; var UsedPorts:byte):integer; stdcall export;
//;get data bits (if are bits as input, then get theirs pull-ups)
begin
if WaitForSingleObject(SerializationEvent,SerializationEventTimeout)=WAIT_TIMEOUT then
begin
ShowThreadErrorMessage;
Result:=DEVICE_NOT_PRESENT;
Exit;
end;
Result:=DEVICE_NOT_PRESENT;
OutLength:=3;
if not SendToDriver(FNCNumberDoGetOutDataPort,0,0,OutputData,OutLength) then
begin
SetEvent(SerializationEvent);
Exit;
end;
UsedPorts:=0;
if (OutLength>0)and(@DataOutByteB<>nil) then
begin
DataOutByteB:=OutputData[0];
UsedPorts:=UsedPorts or 1;
end;
if (OutLength>1)and(@DataOutByteC<>nil) then
begin
DataOutByteC:=OutputData[1];
UsedPorts:=UsedPorts or 2;
end;
if (OutLength>2)and(@DataOutByteD<>nil) then
begin
DataOutByteD:=OutputData[2];
UsedPorts:=UsedPorts or 4;
end;
Result:=NO_ERROR;
SetEvent(SerializationEvent);
end;
//-------------------------------------------------------------------------------------------------------
function DoGetOutDataPort(var DataOutByte:byte):integer; stdcall export;
//;get data bits (if are bits as input, then get theirs pull-ups)
var
Dummy:byte;
begin
Result:=DoGetOutDataPorts(DataOutByte,Dummy,Dummy,Dummy);
end;
//-------------------------------------------------------------------------------------------------------
function DoGetInDataPorts(var DataInByteB, DataInByteC, DataInByteD:byte; var UsedPorts:byte):integer; stdcall export;
//;get data bits - pin reading
begin
if WaitForSingleObject(SerializationEvent,SerializationEventTimeout)=WAIT_TIMEOUT then
begin
ShowThreadErrorMessage;
Result:=DEVICE_NOT_PRESENT;
Exit;
end;
Result:=DEVICE_NOT_PRESENT;
OutLength:=3;
if not SendToDriver(FNCNumberDoGetInDataPort,0,0,OutputData,OutLength) then
begin
SetEvent(SerializationEvent);
Exit;
end;
UsedPorts:=0;
if (OutLength>0)and(@DataInByteB<>nil) then
begin
DataInByteB:=OutputData[0];
UsedPorts:=UsedPorts or 1;
end;
if (OutLength>1)and(@DataInByteC<>nil) then
begin
DataInByteC:=OutputData[1];
UsedPorts:=UsedPorts or 2;
end;
if (OutLength>2)and(@DataInByteD<>nil) then
begin
DataInByteD:=OutputData[2];
UsedPorts:=UsedPorts or 4;
end;
Result:=NO_ERROR;
SetEvent(SerializationEvent);
end;
//-------------------------------------------------------------------------------------------------------
function DoGetInDataPort(var DataInByte:byte):integer; stdcall export;
//;get data bits - pin reading
var
Dummy:byte;
begin
Result:=DoGetInDataPorts(DataInByte,Dummy,Dummy,Dummy);
end;
//-------------------------------------------------------------------------------------------------------
function DoSetRS232DataBits(DataBits:byte):integer; stdcall export;
//;set databits number of RS232
begin
if not(DataBits in [5,6,7,8]) then
begin
Result:=INVALID_DATABITS;
Exit;
end;
DataBits:=DataBits-5;
if WaitForSingleObject(SerializationEvent,SerializationEventTimeout)=WAIT_TIMEOUT then
begin
ShowThreadErrorMessage;
Result:=DEVICE_NOT_PRESENT;
Exit;
end;
Result:=DEVICE_NOT_PRESENT;
OutLength:=1;
if SendToDriver(FNCNumberDoSetRS232DataBits,DataBits,0,OutputData,OutLength) then
Result:=NO_ERROR;
SetEvent(SerializationEvent);
end;
//-------------------------------------------------------------------------------------------------------
function DoGetRS232DataBits(var DataBits:byte):integer; stdcall export;
//;get databits number of RS232
begin
if WaitForSingleObject(SerializationEvent,SerializationEventTimeout)=WAIT_TIMEOUT then
begin
ShowThreadErrorMessage;
Result:=DEVICE_NOT_PRESENT;
Exit;
end;
Result:=DEVICE_NOT_PRESENT;
OutLength:=1;
if not SendToDriver(FNCNumberDoGetRS232DataBits,0,0,OutputData,OutLength) then
begin
SetEvent(SerializationEvent);
Exit;
end;
DataBits:=OutputData[0]+5;
Result:=NO_ERROR;
SetEvent(SerializationEvent);
end;
//-------------------------------------------------------------------------------------------------------
function DoSetRS232Parity(Parity:byte):integer; stdcall export;
//;set parity of RS232
const
ParityNone =0;
ParityOdd =1;
ParityEven =2;
ParityMark =3;
ParitySpace =4;
begin
if not(Parity in [ParityNone,ParityOdd,ParityEven,ParityMark,ParitySpace]) then
begin
Result:=INVALID_PARITY;
Exit;
end;
if WaitForSingleObject(SerializationEvent,SerializationEventTimeout)=WAIT_TIMEOUT then
begin
ShowThreadErrorMessage;
Result:=DEVICE_NOT_PRESENT;
Exit;
end;
Result:=DEVICE_NOT_PRESENT;
OutLength:=1;
if SendToDriver(FNCNumberDoSetRS232Parity,Parity,0,OutputData,OutLength) then
Result:=NO_ERROR;
SetEvent(SerializationEvent);
end;
//-------------------------------------------------------------------------------------------------------
function DoGetRS232Parity(var Parity:byte):integer; stdcall export;
//;get parity of RS232
begin
if WaitForSingleObject(SerializationEvent,SerializationEventTimeout)=WAIT_TIMEOUT then
begin
ShowThreadErrorMessage;
Result:=DEVICE_NOT_PRESENT;
Exit;
end;
Result:=DEVICE_NOT_PRESENT;
OutLength:=1;
if not SendToDriver(FNCNumberDoGetRS232Parity,0,0,OutputData,OutLength) then
begin
SetEvent(SerializationEvent);
Exit;
end;
Parity:=OutputData[0];
Result:=NO_ERROR;
SetEvent(SerializationEvent);
end;
//-------------------------------------------------------------------------------------------------------
function DoSetRS232StopBits(StopBits:byte):integer; stdcall export;
//;set stopbits of RS232
const
StopBit1 =0;
StopBit2 =1;
begin
if not(StopBits in [StopBit1,StopBit2]) then
begin
Result:=INVALID_STOPBITS;
Exit;
end;
if WaitForSingleObject(SerializationEvent,SerializationEventTimeout)=WAIT_TIMEOUT then
begin
ShowThreadErrorMessage;
Result:=DEVICE_NOT_PRESENT;
Exit;
end;
Result:=DEVICE_NOT_PRESENT;
OutLength:=1;
if SendToDriver(FNCNumberDoSetRS232StopBits,StopBits,0,OutputData,OutLength) then
Result:=NO_ERROR;
SetEvent(SerializationEvent);
end;
//-------------------------------------------------------------------------------------------------------
function DoGetRS232StopBits(var StopBits:byte):integer; stdcall export;
//;get stopbits of RS232
begin
if WaitForSingleObject(SerializationEvent,SerializationEventTimeout)=WAIT_TIMEOUT then
begin
ShowThreadErrorMessage;
Result:=DEVICE_NOT_PRESENT;
Exit;
end;
Result:=DEVICE_NOT_PRESENT;
OutLength:=1;
if not SendToDriver(FNCNumberDoGetRS232StopBits,0,0,OutputData,OutLength) then
begin
SetEvent(SerializationEvent);
Exit;
end;
StopBits:=OutputData[0];
Result:=NO_ERROR;
SetEvent(SerializationEvent);
end;
//-------------------------------------------------------------------------------------------------------
function DoEEPROMRead(Address:word; var DataInByte:byte):integer; stdcall export;
//;read EEPROM from given address
begin
if WaitForSingleObject(SerializationEvent,SerializationEventTimeout)=WAIT_TIMEOUT then
begin
ShowThreadErrorMessage;
Result:=DEVICE_NOT_PRESENT;
Exit;
end;
Result:=DEVICE_NOT_PRESENT;
OutLength:=1;
if not SendToDriver(FNCNumberDoEEPROMRead,Address,0,OutputData,OutLength) then
begin
SetEvent(SerializationEvent);
Exit;
end;
DataInByte:=OutputData[0];
Result:=NO_ERROR;
SetEvent(SerializationEvent);
end;
//-------------------------------------------------------------------------------------------------------
function DoEEPROMWrite(Address:word; DataOutByte:byte):integer; stdcall export;
//;write data byte to EEPROM to given address
begin
if WaitForSingleObject(SerializationEvent,SerializationEventTimeout)=WAIT_TIMEOUT then
begin
ShowThreadErrorMessage;
Result:=DEVICE_NOT_PRESENT;
Exit;
end;
Result:=DEVICE_NOT_PRESENT;
OutLength:=1;
if SendToDriver(FNCNumberDoEEPROMWrite,Address,DataOutByte,OutputData,OutLength) then
Result:=NO_ERROR;
SetEvent(SerializationEvent);
end;
//-------------------------------------------------------------------------------------------------------
function DoRS232Send(DataOutByte:byte):integer; stdcall export;
//;send one data byte to RS232 line
begin
if WaitForSingleObject(SerializationEvent,SerializationEventTimeout)=WAIT_TIMEOUT then
begin
ShowThreadErrorMessage;
Result:=DEVICE_NOT_PRESENT;
Exit;
end;
Result:=DEVICE_NOT_PRESENT;
OutLength:=1;
if SendToDriver(FNCNumberDoRS232Send,DataOutByte,0,OutputData,OutLength) then
Result:=NO_ERROR;
SetEvent(SerializationEvent);
end;
//-------------------------------------------------------------------------------------------------------
function DoRS232Read(var DataInByte:byte):integer; stdcall export;
//;read one data byte from serial line (only when FIFO not implemented in device)
begin
if WaitForSingleObject(SerializationEvent,SerializationEventTimeout)=WAIT_TIMEOUT then
begin
ShowThreadErrorMessage;
Result:=DEVICE_NOT_PRESENT;
Exit;
end;
Result:=DEVICE_NOT_PRESENT;
OutLength:=3;
if not SendToDriver(FNCNumberDoRS232Read,0,0,OutputData,OutLength)then
begin
SetEvent(SerializationEvent);
Exit;
end;
if OutLength=2 then
begin
Result:=NO_DATA_AVAILABLE;
SetEvent(SerializationEvent);
Exit;
end;
Result:=NO_ERROR;
if OutLength=3 then
begin
Result:=OVERRUN_ERROR;
end;
DataInByte:=OutputData[0];
SetEvent(SerializationEvent);
end;
//-------------------------------------------------------------------------------------------------------
function DoSetRS232Baud(BaudRate:integer):integer; stdcall export;
//;set baud speed of serial line
//BAUD=12e6/(16*(WORD+1))
var
BaudRateByte:word;
BaudRateDouble:double;
BaudError:double;
MaxBaudRateByte:integer;
const
Error=0.04; //4% max chyba
MaxError=1+Error;
MinError=1-Error;
begin
DoGetRS232Baud(MaxBaudRateByte);
if UARTx2Mode then
begin
MaxBaudRateByte:=4095;
BaudRate:=Round(BaudRate/2);
end
else
begin
MaxBaudRateByte:=255;
end;
Result:=INVALID_BAUDRATE;
if BaudRate >= 12e6/16*MaxError then Exit;
if BaudRate <= 12e6/(16*(MaxBaudRateByte+1))*MinError then Exit;
BaudRateDouble:=Round(12e6/(16*BaudRate)-1);
if BaudRateDouble<0 then BaudRateDouble:=0;
if BaudRateDouble>MaxBaudRateByte then BaudRateDouble:=MaxBaudRateByte;
BaudError:=12e6/(16*(BaudRateDouble+1))/BaudRate;
if BaudError>MaxError then Exit;
if BaudError<MinError then Exit;
BaudRateByte:=Round(BaudRateDouble);
if WaitForSingleObject(SerializationEvent,SerializationEventTimeout)=WAIT_TIMEOUT then
begin
ShowThreadErrorMessage;
Result:=DEVICE_NOT_PRESENT;
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -