//-----------------------------------------------------------------// // Hasler Bern mechanic speedometer DLL // This DLL receives the velocity from LOTUS game, then // writes this value out on the serial port, at 9600 kbps baud rate, // on port number X, where X is given in Teloc_config.txt file. // // Author: Bzmot332 //-----------------------------------------------------------------// library Teloc; uses SysUtils, Interfaces, Dialogs, serial, Classes; //TestU in 'TestU.pas' {Form1}; ->used in example code (lexicon article) //{$R *.res} const C_FNAME = 'Teloc_config.txt'; var tfIn: TextFile; port: integer; DataOut: integer; serialhandle : LongInt; ComPortName : String; tmpstr : String; ComPortNr : integer; writecount : integer; status : LongInt; Flags : TSerialFlags; { TSerialFlags = set of (RtsCtsFlowControl); } // Called at the startup of the game procedure PluginStart(AOwner: TComponent); stdcall; begin // Set the name of the file that will be read Assign(tfIn, C_FNAME); reset(tfIn); readln(tfIn, port); Close(tfIn); //----------------------------------------------------------------------// ComPortNr := 1; //to make sure it has some value ComPortNr := port; //rewrite with the given value from the config.txt str(ComPortNr,tmpstr); ComPortName:= 'COM'+tmpstr+':'; //eg. COM1: ComPortName:= 'COM'+tmpstr; //eg. COM1 //opening serial port Serialhandle := SerOpen(ComPortName); Flags:= [ ]; // None SerSetParams(serialhandle,9600,8,NoneParity,1,Flags); //debug ShowMessage('Pluginstart proc. called!' + sLineBreak + 'File name: ' + C_FNAME + sLineBreak + 'Port: ' + ComPortName + sLineBreak + 'Serial Handle: ' + IntToStr(Serialhandle)); end; // Called before exiting the game procedure PluginFinalize; stdcall; begin SerFlushOutput(serialhandle); // discard any remaining output SerClose(serialhandle); // close serial port end; // only used procedure at the moment procedure ReceiveVarFloat(varindex: word; value: single); stdcall; begin //NOTE: only var.0 is used, for velocity, which is single type case varindex of 0: begin // writing the speed on serial port DataOut := Round(3.6 * value); // so this way we'll write out int, not float numbers (also, in kmph not mps) str(DataOut,tmpstr); writecount := length(tmpstr); status := SerWrite(serialhandle, DataOut, writecount); SerSync(serialhandle); //flush out any remaining before closure end; end; //end of CASE end; procedure ReceiveVarBool(varindex: word; value: boolean); stdcall; begin end; procedure ReceiveVarInt(varindex: word; value: integer); stdcall; begin end; procedure OnConnectingVehicle(name: shortstring); stdcall; begin end; procedure OnUnconnectingVehicle; stdcall; begin end; //function SetButton(eventindex: word): boolean; //begin //end; //function SetFloat(eventindex: word): single; //begin //end; exports ReceiveVarFloat, PlugInStart, OnConnectingVehicle, OnUnconnectingVehicle, PlugInFinalize; begin end.