Skip to content

fix setting instance variable of ttyDUMMY - #4

Open
dlarue wants to merge 1 commit into
krywenko:masterfrom
dlarue:patch-1
Open

fix setting instance variable of ttyDUMMY#4
dlarue wants to merge 1 commit into
krywenko:masterfrom
dlarue:patch-1

Conversation

@dlarue

@dlarue dlarue commented Feb 28, 2022

Copy link
Copy Markdown

The variable was looking for /dev/ttyDUMMYWVC when it resides in /tmp/ttyDUMMYWVC. It was working with only one instance but a second instance would fail to be found.

The variable was looking for /dev/ttyDUMMYWVC when it resides in /tmp/ttyDUMMYWVC. It was working with only one instance but a second instance would fail to be found.
@dlarue

dlarue commented Feb 28, 2022

Copy link
Copy Markdown
Author

looks to be a bit more involved than I first though. The first instance will find no count so $I ends up being -1 which is no good.
So I've added a test for -1:
I=expr $(ps -efww | grep 'tty[W]VCDUMMY' | wc -l) - 1 # for openwrt remove ps arguements -efww
if [ $I == '-1' ]; then
I=0
fi
echo "virtural port " /tmp/ttyWVCDUMMY$I

Then I found that interceptty isn't even started before the first check for ttyWVCDUMMY and it's initialized after a comm failure so the whole setting and echoing of the virtual comm device should be after every call to interceptty.

I can kill this pull request and create another if you'd like?

@krywenko

Copy link
Copy Markdown
Owner

I do not that think that would be correct - interceptty creates the virtual device in /dev/ttyWVCDUMMY grep searches for how many incidences it see and creates a virtual device based on that if it there then the script strips of the relevant data from that virtual device and then stores it in /tmp/ttyWVCDUMMY for secondary processing .. .. there should only one incidences of /dev/ WVCDUMMY unless you are running multiple copies of WVC which you do not need to do you enter all your inverters in the one config file . the script reads the config file and sends the request key for that inverter the corresponding inverter responds and replies and then that data is stored in /tmp/ttyWVCDUMMY.. if it only seeing the one inverter then it would seam the read function for the hc12 it not working for some reason.. but it works fine for my older version using HC12 or modem

@dlarue

dlarue commented Feb 28, 2022

Copy link
Copy Markdown
Author

it was after I did not see any /dev/ttyWVC* devices in /dev which made me think it was looking in the wrong location.
ps -efww | grep '[W]VC /dev' command didn't seem to be finding anything and just grep'ing for tty shows why. There is no "WVC /dev" anywhere to be found.

dlarue@mymachine:$ ps -efw | grep tty
root 1643 1566 1 Feb21 tty1 02:42:23 /usr/lib/xorg/Xorg -nolisten tcp -auth /var/run/sddm/{726fa724-cb50-42d9-b263-e59aad1c347c} -background none -noreset -displayfd 18 -seat seat0 vt1
dlarue 5550 2086 0 09:46 pts/98 00:00:00 grep --color=auto tty
dlarue 23419 21618 1 09:03 pts/95 00:00:32 /bin/bash ./wvc2 /dev/ttyUSB0 ./wvc700-3.ini ff070618 hc
dlarue 30950 23419 0 09:36 pts/95 00:00:00 interceptty -s ispeed 9600 ospeed 9600 -f hex -l /dev/ttyUSB0 /tmp/ttyWVCDUMMY0

hmm, looks like it's creating the front-device in /dev/pts:
dlarue@mymachine:$ ls -l /tmp/ttyWVCDUMMY0
lrwxrwxrwx 1 dlarue dlarue 11 Feb 28 09:54 /tmp/ttyWVCDUMMY0 -> /dev/pts/94

@krywenko

Copy link
Copy Markdown
Owner

hi there I looked through and tried it would seam you only need to change it to tty[W]VC, with out the if statement if nothing is running then it gets 0 as a result and if more then one is running it gets more of a count .. curious you do not get 0 as a result when you run in terminal with out wvc running
ps -efww | grep 'tty[W]VC' | wc -l
or you could just run it does not exist and should list zero as a result
ps -efww | grep 'tty[W]VC11111' | wc -l

@dlarue

dlarue commented Feb 28, 2022

Copy link
Copy Markdown
Author

The original code was looking for "[W]VC /dev" and it was never found no matter if interceptty was running or not. It always returned 0 so as long as you never tried to run two instances it worked fine. I felt that was broken since it always returned 0 so down the rabbit hole I went. LOL

So since it's just naming the /tmp/ttyWVCDUMMY link as long as the returned value valid and different things are good.
ps -efww | grep 'tty[W]VC' | wc -l
does indeed return an increasing number and 0 if none is found. It's still handy to have the "I" variable set when a new interceptty instance is started and echo the new /tmp/ttyWVCDUMMYx link being used.

I tested by starting wvc new and not /tmp/ttyWVCDUMMYx link and it created /tmp/ttyWVCDUMMY0
I tested after opening a file named /tmp/ttyWVCDUMMY0 and then started wvc and it found no comm device then opened /tmp/ttyWVCDUMMY1

Without the setting of "I" var and echoing after each opening of interceptty all you see is the first entry which runs before interceptty is run so it shows /tmp/ttyWVCDUMMY0 as the virtual port even when it's already open by another instance...

example: I have another session editing /tmp/ttyWVCDUMMY0 so if you run "ps -efww | grep 'tty[W]VC' | wc -l" it will turn 1 but you see in the output below, it'll first say /tmp/ttyWVCDUMMY0 is the opened virtual port for this instance but when interceptty is really run, it will open /tmp/ttyWVCDUMMY1 and the added code setting variable "I" and the echo command shows what device really is being used.

$ ./wvc /dev/ttyUSB0 ./wvc700-3.ini ff070618 hc | tee -a mosquitto.log
Using ModemID ff 07 06 18 at port /dev/ttyUSB0 Using inverter list ./wvc700-3.ini on a hc Device
virtural port /tmp/ttyWVCDUMMY0

Inverter Type WVC700 R3

no input from inverter 40000D02

no COM detected
restarting COM
virtural port /tmp/ttyWVCDUMMY1
^C

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants