Recent

Author Topic: Serial port  (Read 2160 times)

Jurassic Pork

  • Hero Member
  • *****
  • Posts: 1272
Re: Serial port
« Reply #15 on: May 24, 2025, 08:54:17 am »
Hello,
To access serial ports on Linux without needing root permissions, you can add your user to the dialout group. This group grants access to serial devices like /dev/ttyUSB0 and /dev/ttyS0
Friendly, J.P
Jurassic computer : Sinclair ZX81 - Zilog Z80A à 3,25 MHz - RAM 1 Ko - ROM 8 Ko

MarkMLl

  • Hero Member
  • *****
  • Posts: 8431
Re: Serial port
« Reply #16 on: May 24, 2025, 09:21:57 am »
-1 can be returned if the device is used by another process or not correct freed from an older process. And only one process can work with this device and you must have the rights to use the device. By default a normal user have no rights for the devices.

The unix default is that serial devices can be shared, that's something I'd possibly change if I did any more work on serial.pp.

First, check that the device exists and the name is correct: don't just thrash around using /dev/ttyUSB, /dev/ttyACM0 etc. at random.

Second, it is conventionally owned by the dialout group. Make sure the normal user is a member of this, logout and log back in to have the new rights.

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Logitech, TopSpeed & FTL Modula-2 on bare metal (Z80, '286 protected mode).
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

Lauriet

  • New Member
  • *
  • Posts: 28
Re: Serial port
« Reply #17 on: May 25, 2025, 03:44:12 am »
From what i can make out socrat is a virtual serial port.....when i write to it nothing comes out of the real port.


I would like to use Serial.pp:

I am connecting an arduino uno board via the usb port.
It is showing up in /dev as 'ttyACM0'
I am a user of dialout group.
I have set permissions of ttyACM0 to include me:

the code is:

Code: Pascal  [Select][+][-]
  1. var
  2. SerFileHandle : LongInt;
  3.  
  4. begin
  5.   SerFileHandle := SerOpen('/dev/ttyACM0');
  6.   if SerFileHandle = -1 then
  7.     write('Error');
  8.   Flags := [];
  9.   SerSetParams(SerFileHandle, 9600, 8, noneparity, 1, Flags);
  10.  
  11. end.
  12.  

Still not opening the port ???????????????????????????

I've just read in serial.pp that seropen returnss 0 if not connected....so what does -1 indicate ???
« Last Edit: May 25, 2025, 03:47:04 am by Lauriet »

ccrause

  • Hero Member
  • *****
  • Posts: 1025
Re: Serial port
« Reply #18 on: May 25, 2025, 11:25:28 am »
I've just read in serial.pp that seropen returnss 0 if not connected....so what does -1 indicate ???

SerOpen calls fpopen which returns either a file descriptor or a negative value to indicate an error.  The man page for open(2) basically agrees with this. Thus there is still an error with your code or setup.  Call fpgeterrno to read the underlying OS error code:
Code: Pascal  [Select][+][-]
  1. uses
  2.   BaseUnix;
  3.  
  4. var
  5.   SerFileHandle : LongInt;
  6.  
  7. begin
  8.   fpseterrno(0);  // optional, just to be paranoid
  9.   SerFileHandle := SerOpen('/dev/ttyACM0');
  10.   if SerFileHandle < 1 then
  11.   begin
  12.     write('Error: ', fpgeterrno);
  13.     Exit;
  14.   end;
  15.  
  16.   SerSetParams(SerFileHandle, 9600, 8, noneparity, 1, []);
  17.   // ...
  18.  end.

The description of the returned error number can be found by calling the errno command from a terminal:
Code: Bash  [Select][+][-]
  1. $ errno 42
  2. ENOMSG 42 No message of desired type

Lauriet

  • New Member
  • *
  • Posts: 28
Re: Serial port
« Reply #19 on: May 25, 2025, 11:58:25 am »
for some strange reason it is working now.
Don't know what i've done ???????????
« Last Edit: May 25, 2025, 12:03:45 pm by Lauriet »

MarkMLl

  • Hero Member
  • *****
  • Posts: 8431
Re: Serial port
« Reply #20 on: May 26, 2025, 01:35:22 pm »
for some strange reason it is working now.
Don't know what i've done ???????????

For completeness, note that some variants of Arduino (i.e. including clones, knockoffs and so on) appear as /dev/ttyACMn and others as /dev/ttyUSBn where n is a number.

If you have problems using serial.pp please could you continue here rather than staring a new thread, to make sure I see it.

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Logitech, TopSpeed & FTL Modula-2 on bare metal (Z80, '286 protected mode).
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

Lauriet

  • New Member
  • *
  • Posts: 28
Re: Serial port
« Reply #21 on: May 27, 2025, 07:08:04 am »
Yep, My arduino uno rev3 appears as ttyACM0

I'm not sure how it started working....I'm guessing it was somewhere with me adding me to "dialout" and/or setting the file permissions on /dev/ttyACM0 and/or rebooting for these to take affect.
Anywho, the next challenge is the get the arduino to output the right thing to program an at89s51 thru its ISP pins......Always problems to solve. ::)


MarkMLl

  • Hero Member
  • *****
  • Posts: 8431
Re: Serial port
« Reply #22 on: May 27, 2025, 10:01:31 am »
Yep, My arduino uno rev3 appears as ttyACM0

Watch out for things which are /nominally/ Unos but also appear on /dev/ttyUSB0. It all depends on whether whoever made it uses a second AVR chip to provide the TTY/serial -> USB interface, or a knockoff FTDI chip.

Quote
I'm not sure how it started working....I'm guessing it was somewhere with me adding me to "dialout" and/or setting the file permissions on /dev/ttyACM0 and/or rebooting for these to take affect.
Anywho, the next challenge is the get the arduino to output the right thing to program an at89s51 thru its ISP pins......Always problems to solve. ::)

I thought it indelicate to remind you that I'd specifically said you'd need to logout after adding yourself to the dialout group :-) You probably aren't able to make permissions/ownership of serial ports stick, since they're set from defaults when the device is plugged in (or a plugin is simulated when the computer boots)... there's a way round that described in the installation notes for things like Teensies.

I've not tried writing code to program an AVR chip, but at one point I was modifying the boot loader to work on a card I'd "upcycled" from a scrap washing machine and found it useful to write something to check what speed the target device was running at and what DTRt state reset it https://github.com/MarkMLl/ping-arduino-loader

There's a couple of demo programs at https://github.com/MarkMLl/serialcomms which might be useful, one of them simply echoes serial stuff and the other is a simple terminal emulator. However note that the second is somewhat topheavy on all the stuff needed to get a standard Linux console to work as expected (i.e. "raw" rather than "cooked").

Also the locateports.pas has SerOpenLocked() and SerAvailable(), the latter tries to accommodate various kernel quirks that I've learnt about the hard way. Apart from that, the serial.pp stuff has stood up fairly well.

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Logitech, TopSpeed & FTL Modula-2 on bare metal (Z80, '286 protected mode).
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

 

TinyPortal © 2005-2018