From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: * X-Spam-Status: No, score=1.3 required=5.0 tests=BAYES_00,INVALID_MSGID, MSGID_RANDY autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,6551e8ab1fe1fab7,start X-Google-Attributes: gid103376,public From: tilmanglotzner@my-deja.com Subject: how to access a (serial) device (linux) Date: 2000/01/27 Message-ID: <86op66$lu9$1@nnrp1.deja.com>#1/1 X-Deja-AN: 578165986 X-Http-Proxy: 1.0 x24.deja.com:80 (Squid/1.1.22) for client 210.158.194.36 Organization: Deja.com - Before you buy. X-Article-Creation-Date: Thu Jan 27 06:39:02 2000 GMT X-MyDeja-Info: XMYDJUIDtilmanglotzner Newsgroups: comp.lang.ada X-Http-User-Agent: Mozilla/4.0 (compatible; MSIE 4.01; Windows NT) Date: 2000-01-27T00:00:00+00:00 List-Id: Hello, I wrote a program to access serial port via the device file. One task reads on the port, another task writes to the port. The tasks somehow seem to block each other, and an antenna controller connected to the serial port does not receive anything. 1) Is accessing the serial port via a device file the wrong approach ? Is it better to do this by an interrupt service routine ? A sample which I could reuse would be very, very helpful here :-) 2) Maybe the processes are in a dead lock because 2 processes try to access the same file. Is it feasible to access a device file from 2 task ? 3) Maybe it is better to access the device file from only 1 task. I would need to open the file as read/write. Text_io seems not be capable of this.Are there other packages which allow opening (device) file as read/write ? Thanks, Tilman === Here the code ============================ with Text_IO;use Text_IO; with System; use System; package body Ser_read is package Int_Io is new Integer_IO (Integer); use Int_Io; task body Read is ReadPtr : File_Type; Str : String(1..100); Az : String(1..20); El : String(1..20); DeviceB : String := "/dev/ttyS0"; End_Flag : Boolean := False; I : Integer; LineCount: Integer := 0; Wait : Duration := 1.0; begin Put_Line ("[Read] : Started"); while (End_Flag = False) loop select accept Init do Put_Line ("[Read] : Open " & DeviceB & " for read ..."); Open (ReadPtr,In_File,DeviceB,"SHARED=NO"); Put_Line ("[Read] : Opened for Read " & DeviceB); end Init; or accept Read_Orientation do Put_Line ("[Read] : Read_Orientation Signal received"); Write.Send_Command("C2"); Put_Line ("[Read] : Reading from " & DeviceB & ";"); Get_Line(ReadPtr,Az,I); -- Get_Line(ReadPtr,El,I); Put_Line("Azimuth : " & Az & ";"); Put_Line("Elivation: " & El & ";"); end Read_Orientation; or accept Stop do Put_Line ("[Read] : Stop Signal received"); End_Flag := True; end Stop; end select; end loop; Put_Line ("[Read] : Close " & DeviceB); Close (ReadPtr); Put_Line ("[Read] : Closed " & DeviceB); Put_Line ("[Read] : Terminating task ..."); End Read; task body Write is WritePtr : File_Type; DeviceA : String := "/dev/ttyS0"; End_Flag : Boolean := False; begin Put_Line ("[Write] : Started;"); while (End_Flag = False) loop select accept Init do Put_Line ("[Write] : Open " & DeviceA & " for write ..."); Open (WritePtr,Out_File,DeviceA,"SHARE=NO"); Put_Line ("[Write] : Opened for Write " & DeviceA); end Init; or accept Send_Command(Comm: in String) do Put_Line ("[Write] : Command Signal received: " & Comm & ";"); Put_Line (WritePtr,Comm); Put_Line ("[Write] : Command sent: " & Comm & ";"); end Send_Command; or accept Stop do Put_Line ("[Write] : Stop Signal received"); End_Flag := True; end Stop; end select; end loop; Put_Line ("[Write] : Close " & DeviceA & " ..."); Close (WritePtr); Put_Line ("[Write] : Closes " & DeviceA ); Put_Line ("[Write] : Terminating task ..."); end Write; end Ser_read; =========== and the code of the main program With Text_IO; use Text_IO; with Ser_read; procedure SerialOpen is FilePtr : Text_IO.File_Type; CStr : String (1..8); I : Integer; C : Character; begin Put_Line ("[Main]: Start"); -- Ser_Read.Read.Init; Ser_Read.Write.Init; CStr := "W020 015"; Put_Line ("[Main]: Initiate rotor command: " & CStr(1..CStr'Last)); Ser_Read.Write.Send_Command(CStr); Put_Line ("[Main]: Press "); Get (C); Put_Line ("[Main]: Initiate rotor command: C2"); -- CStr := "C2"; Ser_Read.Read.Read_Orientation; Put_Line ("[Main]: Press "); Get (C); CStr := "W000 000"; Put_Line ("[Main]: initiate rotor command: " & CStr(1..CStr'Last)); Ser_Read.Write.Send_Command(CStr); Put_Line ("[Main]: Initate termination of Read task.. " ); Ser_Read.Read.Stop; Put_Line ("[Main]: Initate termination of Write task.. " ); Ser_Read.Write.Stop; end; Sent via Deja.com http://www.deja.com/ Before you buy.