How can I have better control over my serial COM ports in Windows 10? - ports

I need to use a serial port with a LabVIEW program I'm making. I'm connecting the machine I'm controlling, which uses RS232, via a serial/USB converter. Windows (10) automatically installed the drivers for this converter, and I know it's working correctly.
If I look in Device Manager, it's there under Ports:
And I can successfully communicate with the machine using a Python script I happen to have:
import os
import sys
import glob
import operator
import serial
import time
from string import *
from time import strftime
# Initialize serial
sii=serial.Serial('COM3',1200,timeout=0.5)
print( "BEGIN")
sii.write(b"T\r")
time.sleep(1)
temp=sii.read(100).decode("utf-8")
sii.close()
print(temp)
print ("done")
I know this works, because it fetches the right information from the machine. It prints the correct "temp" value, no problems.
However, it's not connecting when I try it in LabVIEW, but my question isn't really about that. What it is about is, when I try it in LabVIEW, and then try the same exact python script that just worked, I get this error:
serial.serialutil.SerialException: could not open port 'COM3': PermissionError(13, 'Access is denied.', None, 5)
So clearly, LabVIEW is still using COM3, or something. My question is, how can I "kill" that connection?
I read on another Stack Overflow thread that you can try right clicking COM3 in Device Manager, disabling it, and then enabling it, but I've tried this (without rebooting, as it asks you to do), and it doesn't work. It works again if I reboot, but that's not really a solution.
Is there some smart way to do this? I can't use Portmon because I'm using 64 bit Windows, and I've tried the methods of running it in compatibility mode, which haven't worked either. I downloaded "AccessPort", but to be honest, I don't really know what to do with it; ports are somewhat black magic to me. Ideally, I'd have some sort of program that shows what ports are connected to what applications, and let me sever those ties, but that's probably a naive view of it.
What can I do to proceed? thank you.

Related

How do I get bluez 5 to accept a fixed pin?

I can find nothing on how to do this. I am programming an Intel Edison in C and an Android phone in Java. I want to pair the Edison from the Android phone. I would think simple pairing (sspmode 1) would work but I get an error message on the phone about a wrong pin where no pin was requested. With sspmode 0 I get asked for a password but have no idea what it is as it is randomly generated in my NoInputNoOutput Edison. We have everything else working. If we pair from Edison manually, the rest of the code can connect and send bluetooth messages back and forth from the Edison to the phone. But pairing from Edison to any random phone that walks by is not acceptable. I think it is called Bluejacking.
I have seen some posts about using simple-agent but frankly what I understand is that BlueZ security changed so much between 4 and 5 that most all that I see doesn't work. I also see that the switch from 4 to 5 broke a lot of systems so I don't feel alone. I would try it but simple-agent is not on Edison and I have not found a procedure to install it. And as I don't know if the little I can find applies to version 5 as it all references version 4 I am feeling a little lost.
Can anyone point me in the right direction to something that will work on BlueZ 5? I am on 5.18.
The solution presented on the last post of this article does work
http://www.linuxquestions.org/questions/linux-wireless-networking-41/setting-up-bluez-with-a-passkey-pin-to-be-used-as-headset-for-iphone-816003/
Edit simple-agent, put it somewhere, make it executable, put the missing files in the same directory and run it. It must stay running for it to be active.
In my case, the missing file was bluezutils.py.
Run hciconfig hci0 sspmode 0 first
Pl use Bluz5.30.
Initially it was really difficult to bring up bluetooth using Bluez 5. It seems it was okay with Bluez 4.I have tried different versions of Bluez 5 on my LFS build. Even up to Bluez 5.28 it was not satisfactory. Now it is Bluz5.30, with this, LFS doc and lot of trail, I could manage. I feel Bluez is one of the most badly documented user unfriendly software. I also feel it is very buggy. It can hang machines forcing to hard boot the system. I have seen bluetooth forcing the Android phone also to reboot. So it is important to get the latest version of the software. But to make the bluetooth speaker work Pulseaudio was needed. It is better to get the latest version; here also LFS doc was fine.
So the process of connecting speaker was using bluetoothctl is as follows;
>> power on
>> scan on
>> pairable on
>> pair <device>
>> agent on
>> default-agent
Now the actual sound. Here pactl and pacmd are useful.
paplay -d can test the devices.
using pacmd with command 'list-sinks' can show the devices.
pacmd ->list-modules can show the modules loaded.
How to change automatically the audio output to bluetooth speaker when it is connected?
For me in one machine it was working fine, with an identical LFS in another machine it was not working. Finally it was identified as a
missing module module-device-manager with arg do_routing=1.
Once it was loaded everything was fine. This particular module was not shown in the pulse configurations. So I have to find that and load,
pacmd
load-module module-device-manager do_routing=1
One can add a line in the default configuration file available in /etc/pulse.or one can add it in the user configuration file also.Now to make the new bluetooth speaker being used to play sound. For that issue the command 'move-sink-input ' using pacmd. You can find the sink names my issuing the command 'list-sinks'.
If your speaker is not connecting, it may be that it is already connected elsewhere. If it is not so, remove-device; scan on; pair; and connect using bluetoothctl. I was worrying how to make file transfer using bluetooth (Bluez5). Actually very little information is available in LFS documention or in general in the NET. This very true and unfortunate about Bluez in general. They do not provide any real user doc or nothing is available in net. So the steps are as follows:
You need to install OBEX library. Then you build Bluez5 (if it not done already). It will install obexd. After installation you can find obexd in $PREFIX/libexec/bluetooth/obexd.This is where you find bluetoothd also. One generally makes a link for bluetoothd in /usr/sbin. A similar link can be made for obexd also. Once you start bluetoothd and obexd you can find object transfer profiles in bluetoothctl->show.If you need a phone to push objects to the computer, you need to run obexd with options '-a' and '-r '. if '-a' is not given phone will fail to send the file. Now how to push a file from Computer to Phone. For this you need obexctl, I do not think it is a finished tool, and it will not be installed while we build Bluez 5. I have seen it in the source tree and copied to /usr/bin/. It should be used to connect the Phone and when the connection is established one can 'send ' and you have to accept the request in the phone.
Starting obexd as a deamon was a problem. When obexd was tried on a text terminal (init 3) it was not possible to start since it needs a dbus session which in turn needs X display. It means one need to login an X seession before you start obexd. If you dissable X while building DBUS (--without-x) then Window Managers will not work. But there is solution with 'dus-run-session < command> [args]'. That means you can start a service obexd (like bluetoothd) in the system start-up. So just by switching on the Computer ( if pairing, trusting etc... was done earlier) one can push files from Phone to computer.
>> connect <device>
Second time onwards just connection is fine. Probably you can trust the device.
>> trust <device>

Is it a good idea to use a Screensaver on a raspberry pi as digital signage?

I asked this question in the Raspberry PI section, so please forgive me for posting this here again. Its just there doesn't seem to be as active as this section of the forum. So, onto my question...
I have an idea and I'm working on it right now. I just wanted to see what the community's thought was on using a screensaver as digital signage. Every tutorial I've read shows someone using chromium in kiosk mode, and while that's fine and works well for some uses, it doesn't work for what I need. I have successfully completed a chromium kiosk, and it was cool. But the signage that I need to create now, has to work without internet. I've thought about installing LAMP locally on the PI, and still using chromium. I still may have to if this idea doesn't pan out. All I need from the signage is a Title Message in the top center, and a message body underneath it, with roughly 300-400 character limit. My idea is to write a screensaver module, in C, that will work with a screensaver such as xscreensaver. The module would need to be able to load messages from a directory on the pi. Then for my clients to update their signage text, I would write a simple client that sent commands as well as the text via SSH to the pi. I want to know what other people think about this. Is it a good idea? Bad idea? Should I "waste" my time doing something like this?
Thanks in advance.
I am already using a rPi as digital signage, just over a year. I am using two different setups:
version 1 uses Raspian loading xdesktop and qiv image viewer to cycle images stored on the Pi itself, synchronized with a remote server. The problem I found was power and SD stability, when the power fails, which it will do no matter what, just when... The Sd card can become corrupt due to all the writing that Raspian does all the time. Certainly does not really need to write to SD.
version 2 uses a RO-filesystem and a command line image tool. Uses the same process to show images from local, and sync with server. But power fail causes no ill effects.
I am not using screensaver to display images, that seemed redundant to me, and unnecessary to wait for the SS to start just to display the images.
Some of the images are created using imagemagik, which is nicely dynamic where needed.

TCP/IP Programming in C

I have an exam on tomorrow on TCP/IP programming. Following is one of the previous question on this paper.
Write and run a client and a server program. Using C language in UNIX, with the
following specifications :
• A TCP client program will send a range of number (e.g. 1 to 10) to the server.
• TCP server accept the number range from client and send back the sum of the
number range. Client will print the result.
I dont know how to setup the compiler and other settings to run this tcp ip programs. When I search online, I got two different programs, one for Client and another For server. Some please tell me how can i run these programs to get desired output. What kind of compiler should I install on my system.( I am using windows 7) ??
Since the assignment requires your code to work on a Unix system, you first need to install one. Follow these simple steps to install a virtual Unix environment on top of your existing Windows installation.
Download and install VirtualBox for Windows.
Download & unpack this Ubuntu 12.10 disc image (NOTE: Requires 7-Zip).
Launch VirtualBox and create a new Virtual Machine (name it Ubuntu).
In the "Virtual Hard Disk" settings, select "Use existing hard disk" and select the image file you just downloaded (NOTE: It's filename should end in ".vdi").
Run your new Virtual Machine. You should see the Ubuntu splash screen.
Login with username ubuntu and password reverse (NOTE: Case Sensitive!).
Open up Terminal and type sudo apt-get install build-essential (NOTE: when Terminal prompts you for a password, use reverse).
You should (with hope) have everything you need for your assignment. For more information on network programming, consult Beej's Guide to Network Programming -- Using Internet Sockets.
You need to open two different terminals on your system.
In the first terminal compile and run the server.c program.(make sure either you listen to all ips or your host ip(atleast).
while this is running.(it will wait for a request from your client program)
Run the client program in the other terminal.
Hope this solves the problem!
For details on how to create and run a file in unix refer http://www.wikihow.com/Compile-a-C-Program-Using-the-GNU-Compiler-%28GCC%29
P.S: you can do the same in win7 if iam not wrong only that terminal here in called command prompt!
Post the results if possible!
Download a thing called VMWare player. And look for a Ubuntu image that you can load with the VMWare player. That way, you will have a little Linux virtual machine that you can run inside or along with Windows 7. You can use the compiler GCC in your Ubuntu or whatever other Linux virtual machine. And get lots of coffee. Blargle is correct, but I think my suggestion is a little better, because you end up having a fairly complete Unix type environment to develop in. Blargle's way put Unix tools on top of Windows, which I find to be kind of clunky.
I learnt socket programming from this site. He has given everything in detail . Download an Vmware workstation and load up ubuntu . Understand the programs they are pretty much straight forward .
Maybe you can try to look at Network Socket on the web. You can easily find a lot of good tutorial that can answer your question.
You can use the compiler you want on your system, depending on what are you using now.

Launch OpenGL app straight from a windowless Linux Terminal

How exactly would one go about getting an OpenGL app to run fullscreen straight from the terminal (Ubuntu Server 9.04)? I've developed an application for visual diagnostics on my server, but, I'm not totally sure the best way to get it to run in a windowless environment.
Ideally, I would run my program:
./visualdiagnostics
and have that launch the OpenGL app. Then, via a simple Ctrl+X key binding, I'll kill the app and go back to the terminal.
Do I need to install X11 and then somehow launch it from within the program? What would be the best way to detect if it's already running and, start/stop it if necessary?
And FYI: No, I'm not trying to get this to run over Putty or anything... I have a monitor hooked straight up to the server. The server has proper video drivers installed.
There are several parts to your task. Keep in mind that some of this can be very distro-specific; but since you said Ubuntu we'll talk Ubuntu!
Also you tagged this question C however I am starting off with a common Linux pattern: a native application with a Bash shell script wrapper. Perhaps once you get things working well you might fold that functionality into C if you have to.
Detecting whether X is running
Being root can help a lot. Some things that work.
pgrep Xorg
Check whether /var/lib/gdm/:0.Xauth exists. This will be there even if nobody has logged in but GDM is running.
ls -l /home/*/.Xauthority (Even if you're not root you can at least confirm whether you are running X.
Piggybacking an existing X session
You did not specifically mention it but if you are root at the console, or if you want to run the app as the same user who is already logged in, it's pretty easy.
You have to get the DISPLAY and XAUTHORITY environment variables right, and once you do you can use the existing X display.
For DISPLAY you might just assume :0 or you could find an existing X program (x-session-manager is the GNOME standard) and read its environment from /proc/PID/environ. Variables are in key=value format delimited by a null byte. For example, if its PID is 12345:
cat /proc/12345/environ \
| ruby -ne 'puts $_.split("\0").select {|e| e.starts_with? "DISPLAY=" }'
For XAUTHORITY you could get it the same way. Or if you prefer guessing, it's almost always /home/whoever/.Xauthority
Once you have those two variables, running X code is easy, for example:
env DISPLAY=:0 XAUTHORITY=/home/brian/.Xauthority ./visualdiagnostics
Stopping X
This one is easy if you're root: /etc/init.d/gdm stop. killall Xorg will work too.
If you are a user, kill your own Xorg or x-session-manager process. (I'd welcome input from others for the canonical way to do this. Maybe some dbus-send message?)
Starting X
I would recommend xinit whose goal in life is to fire X and run exactly one program.
For example: xinit ./visualdiagnostics
You can also tell xinit what resolution to run X at which may or may not be important to you. (This becomes important in the full-screen section below.)
The problem with this is you will have no window manager— no maximize and minimize buttons. It's not just cosmetic. Usually an app is useless because a popup window cannot be moved or you cannot focus on the right input field. However if you have a special app it could be sufficient (see full-screen below).
The next step would be my answer to everything: another shell script wrapper! Something simple that starts the window manager and then becomes your program should work.
#!/bin/bash
#
# Start visualdiagnostics once xinit calls me.
/usr/bin/metacity& # Or ratpoison, or fluxbox, or compiz, etc.
exec ./visualdiagnostics
It's important to exec (become) the main program because once that first program exits, X will shut down.
Running fullscreen
I am not 100% certain on this. Some ideas:
Try the standard X -geometry parameters to set 0,0 as the upper-left corner and +x+y for your horizontal and vertical size. How do you know the size? Either you hard-coded it when you launched xinit or you could ask the X server. xwininfo -root will tell you and there is an xlib API call that would do that too—check the xwininfo source I guess.
Your app itself can request maximization and/or resizing to fill the screen. I'm not familiar but it is definitely in the X API.
Some of the more configurable window managers can be pre-configured to run you maximized already. This is probably what I personally would check first. Your wrapper script could create a $HOME/.fluxboxrc just by echoing some hard-coded configs > the file.
Summary
The others are right. X is not strictly necessary sine OpenGL can run against a framebuffer. However considering how ubiquitous X is and how much work has gone into automating it for distributions, I would probably invest my effort into the X route as it might be easier long-term even though it's a little convoluted.
(By the way, I sincerely hope when you say "terminal" you mean you are at the text console, not gnome-terminal that would be awful! :)
Well I am clearly not sure my answer might help you out.
Long ago when I was student, I manage to do so (launching an openGL app from a terminal only linux installation) by installing frame buffer. As long as I remember I needed to recompile my kernel (as framebuffer was/is a kernel module).
This was maybe 5 years ago on a debian distrib, and I don't know how does it work now for up-to-date debian distrib as Ubuntu. Maybe framebuffer is compiled statically in the binary kernel provided by default with Ubuntu. May be not. Maybe framebuffer is irrelevant now... Or I may be totally wrong and not remembering every details of my own adventure 5 years ago now ..
Have a look on Google ! ;-)
Hope it will help...
**
Update:
**
What is frame buffer ?
How to install it? Here or there
As yves pointed out, you can avoid running the X server if you use the framebuffer. Actually, the framebuffer modules are often yet available (for example, they are used to have the tux logo during the kernel start or a text terminal with fancy images in the background), this anyway depends on the distribution and the settings you are using.
The kernel side is quite primitive so I'd suggest to use some higher level library such as DirectFB. The framebuffer is usable without problems but don't expect the same maturity level than a full blown X server.
Are you trying to have the video be on the monitor connected directly to the computer?
Is X running on the server?
If X is running, you can do
export DISPLAY=:0.0
which tells X apps to connect to the X server at localhost, rather than where' you're coming from.
If you're actually logging in locally (from a direct terminal) ... yes, you need X installed and running.

RDP connectivity/responsiveness test

I want to write an app to test whether a Windows machine is responding correctly to RDP (Remote Desktop) - i.e. to check if the machine not only allows the connection, but is also responding normally, and is not hung or otherwise responding abnormally.
Is there a library or utility that I can use to do this? My searches turned up full RDC clients, but I'm hoping there's something out there at least offers an API for testing. I would most like to use Java or a scripting language to do this, but I'm open to suggestions.
You can find some good answers in this question: Programmatically create and launch and RDP session (without gui)
Because RDP is a constantly evolving proprietary protocol, i'm guessing there isn't some simple open-source code you can take and use. This leaves us with two possible paths to follow:
Use Microsoft RDP ActiveX control (on Windows)
Launch mstsc.exe and send keyboard events to it (also on Windows, using your favorite language)
For the second option, I suggest AutoHotkey. It is perfect for automating windows programs and comes with a powerful library. It also has a strong comunity behind it so you can find lots of useful scripts on the internet. I use it to control winamp (like 'i hate this song! delete it and move to next')(well, technically 'move to the next song and delete the previous' because you can't delete the file while in use but you get the idea). If you choose this path, i can help you with the script.
Found this on Experts Exchange:
use Net::Telnet ();
$t = new Net::Telnet (Timeout => 10, Prompt => '', Port >= 3389);
if($t->open("computer.name.or.ip")) {
print "Connect successful\n";
}
else {
print "Could not connect\n";
}
The idea was to attempt a connection and if it can't connect within 'x' amount of seconds, assume it isn't going to work. Gets a bit more complicated if you're trying to see if a login for a specific user works or not, but this should at least get you started.
NOTE: As pointed out in the comments, the original solution left out the RDP port, so I included that in this...

Resources