pymodbus USB connection issue - modbus

I have a Click PLC that I am trying to read coil data from. I am using pymodbus, but I am getting a connection error. The only issue I can come up with is that I don't know if the port entry is correct. I am using an RS-232 converter to USB. The USB is on com4. This there a reason I can't get a connection. Simple code is below.
Thanks,
Marc
from pymodbus.client.sync import ModbusSerialClient
click = ModbusSerialClient(method='rtu',port='com4',baudrate=9600,parity='O')
outputLight = click.read_coils(8193,1,unit=1)
print outputLight

You're missing something like:
click.connect()
After defining your connection and before reading coils.
As you say it seems some of your settings are not correct, maybe you can try something like QModMaster (I'm assuming you're on Windows). It will be easier to try different settings and ports faster, just to make sure you have the correct port at least. See here: https://sourceforge.net/projects/qmodmaster/

Related

One time Internet Connection Check swift

I need to check the internet connection of a user for one time.
I thought of something like Device.isConnectedToTheInternet but I didn't find something similar...
Every solution that if found was like an internet monitor over time, but that's not exactly what I need.
Someone ideas?
Thanks, Boothosh
As Rob Napier mentioned, it looks like the only thing readily available is the NWPathMonitor, which you can use to check the 'connectivity' to a certain location, like www.google.com, or something else that would be relatively trustworthy to be available 24/7, or just the URL you are about to try and use. Here is a short HackingWithSwift tutorial for NWPathMonitor.
I know this isn't exactly your current situation, but in my projects (and a lot of peoples projects) using an API like AlamoFire is pretty common, and has a ton of usefulness for creating GET/PUT/POST/DELETE requests and of course, has a NetworkReachabilityManager which can be used to make a convenient global function for a simple true/false result for 'isConnectedToInternet' like this:
/*
Connectivity
Struct
Utilizes AlamoFire to check for network availability.
isConnectedToInternet should return true in all cases the phone has access (Cellular, No cellular + wifi, Cellular + wifi, wifi)
*/
struct Connectivity {
static let sharedInstance = NetworkReachabilityManager()!
static var isConnectedToInternet:Bool {
let connected = self.sharedInstance.isReachable
return connected
}
}//end Connectivity
See NWPathMonitor().currentPath. It will tell you the current path. This is only occasionally useful, since "connected to the internet" is not a meaningful condition. There is not concrete definition of "the internet." But you can use the NWPath to answer some questions you probably are looking for. The fact that there is an NSPath available does not mean that you can actually connect to something on "the internet." The only way to know that is to send a packet and get a packet back. So if your real question is "can I connect to a specific host," then you're going to need to send packets to that host (and that still won't prove that you can send packets to the host in the future).
All that said, there is a little UI-level usefulness to asking "if I tried to connect, would it certainly fail?" And currentPath can help you answer that. It just can't tell you if it would succeed.

How to talk to this A/D Converter in Linux (ADS7138)

For a project I'm thinking of using this relatively new IC from TI - the ADS7138. The issue (I believe, though I may be wrong) is that there is no driver for this chip in the kernel. Does anyone have any suggestions for a work around to talking to this driver? Is there another driver I could use or am I stuck writing a custom driver specific for this IC?
I've worked on a board bring-up project with the same IC. I couldn't find a driver for it so I wrote one myself. I hope it works for you as well:
ADS7138 Driver
Till you find a compatible kernel driver or develop one yourself, you can quickly experiment with the ADC from user space using the i2c-tools. You can use either the command line tools or use the API to write your own app, but be cautious if you use the command line tools like i2cget(8), first read the man pages and pay attention to the warning section.
To use the API, open(2) the i2c device, set the slave address with ioctl(2), then use smbus APIs like i2c_smbus_write_word_data(), i2c_smbus_read_word_data() etc. You may take a look at the tools code like i2cget.c itself to see how the API is used. Following is a simple code to read a register from an I²C chip connected to /dev/i2c-0.
int fd = open("/dev/i2c-0", O_RDWR);
ioctl(fd, I2C_SLAVE, slave_address);
__s32 res = i2c_smbus_read_word_data(fd, register_address);
close(fd);
See kernel documentation or the web about i2c/smbus and instantiating i2c devices for more details.

Set up ELM327 to behave like FTDI - just forwarding commands without OBD init

My first question on here so I'm not sure if that's the right forum.
I've connected with my car's ECU K-Line through FTDI-OBD cable and terminal. Found it's something like KWP2000 but without preinit hassle. I just send it commands on 9600 baud, even parity, 1 bit stop and got a reply with VIN number. When I try to send same command with ELM327 it doesn't work and I believe because of ELM adding something, either initialisation of the KWP or adding some checksum or additional info and it doesn't work.
I've already tried using
ATSP5
ATIB96
ATBI
And it still doesn't respond eg. VIN message from sending same command.
My point is to get to secret sensors data from $21 because there is a little info in regular Mode01. And I want to use ELM327 because I wanted to use Android phone to display the data.

Disconnect from current internet connection in Swift 2

Is it possible to connect and disconnect to some available network connection with swift, cocoa?
///Addition
So.. I found the NSNetworkInterface, but can't understand how to turn it on or off. Need some little example, just explain, what call -> what get
Is it possible to connect and disconnect to some available network connection with swift, cocoa?
You can't do any of this on iOS, of course, since your code will never run with sufficient privileges and the necessary frameworks probably aren't available. You asked about Cocoa, though, not Cocoa Touch, so I'm presuming you're talking about MacOS X.
I assume that you mean actually connecting to a network rather than just connecting to some host over an established network. To do that, you need to change the system configuration. It is possible to do that, although you'll need to work at a lower level than Cocoa and instead use the SystemConfiguration framework to change the configuration registry. Your code will have to be running with root privileges in order to work, and that alone may make the process untenable depending on your situation. You can find complete instructions and code at Programmatically changing network configuration on OSX. Note that the article dates from 2011, so it's possible that things have changed enough that the advice there no longer works, but it will at least point you in the right direction.
The article obviously predates Swift, but I don't see anything there that wouldn't work in Swift.

I2cSlave reading issue on lpc1343

I'm trying to use the lpc1343 as a i2cslave to transmit some data. Writing to the board gives no problems and works exactly as I want it.
However, reading from the board gives problems. It seems I'm not getting any data back although I am sending the right commands. Whenever I try to debug it my board just hangs and I have to reset the driver and my pc to get it running again.
Also, I made a LED go on/off whenever I try to read from it. It only does this once and whenever I try to do it again nothing happens. I think the I2c is stopped then but I have no idea why.
I have found the example code on the website once but now it seems to be gone. Does somebody have an updated I2cslave code?
Which operating system are you writing code for and how can you tell that writing to the i2c chip is successful?
If the write function returns, it could be that the message has been sent but the chip is in a weird configuration that doesn't act on the message received.