Re: [Numpy-discussion] converting list of int16 values to bitmask and back to list of int32\float values
not sure what you are getting from: Modbus.read_input_registers() but if it is a binary stream then you can put it all in one numpy array (probably type uint8 (byte)). then you can manipulate the type with arr.astype() and arr.byteswap() astype will tell numpy to interpret the same block of data as a different type. You also may be able to create the array with np.fromstring() or np.frombuffer() in the fisrst place. -CHB On Thu, Sep 14, 2017 at 10:11 AM, Nissim Derdiger wrote: > Hi all! > > I'm writing a Modbus TCP client using *pymodbus3* library. > > When asking for some parameters, the response is always a list of int16. > > In order to make the values usable, I need to transfer them into 32bit > bites, than put them in the correct order (big\little endian wise), and > then to cast them back to the desired format (usually int32 or float) > > I've solved it with a pretty naïve code, but I'm guessing there must be a > more elegant and fast way to solve it with NumPy. > > Your help would be very much appreciated! > > Nissim. > > > > My code: > > def Read(StartAddress, NumOfRegisters, FunctionCode,ParameterType, > BitOrder): > > # select the Parameters format > > PrmFormat = 'f' # default is float > > if ParameterType == 'int': > > PrmFormat = 'i' > > # select the endian state - maybe move to the connect > function? > > endian = ' > if BitOrder == 'little': > > endian = '>I' > > # start asking for the payload > > payload = None > > while payload == None: > > payload = Modbus.read_input_registers(StartAddress, > NumOfRegisters) > > parse the answer > > ResultRegisters = [] > > # convert the returned registers from list of int16 to > list of 32 bits bitmaks > > for reg in range(int(NumOfRegisters / 2)): > > ResultRegisters[reg] = > struct.pack(endian, payload.registers[2 * reg]) + > struct.pack(endian,payload.registers[2 * reg + 1]) > > # convert this list to a list with the real parameter > format > > for reg in range(len(ResultRegisters)): > > ResultRegisters[reg]= > struct.unpack(PrmFormat,ResultRegisters(reg)) > > # return results > > return ResultRegisters > > ___ > NumPy-Discussion mailing list > NumPy-Discussion@python.org > https://mail.python.org/mailman/listinfo/numpy-discussion > > -- Christopher Barker, Ph.D. Oceanographer Emergency Response Division NOAA/NOS/OR&R(206) 526-6959 voice 7600 Sand Point Way NE (206) 526-6329 fax Seattle, WA 98115 (206) 526-6317 main reception chris.bar...@noaa.gov ___ NumPy-Discussion mailing list NumPy-Discussion@python.org https://mail.python.org/mailman/listinfo/numpy-discussion
[Numpy-discussion] ANN: SfePy 2017.3
I am pleased to announce release 2017.3 of SfePy. Description --- SfePy (simple finite elements in Python) is a software for solving systems of coupled partial differential equations by the finite element method or by the isogeometric analysis (limited support). It is distributed under the new BSD license. Home page: http://sfepy.org Mailing list: https://mail.python.org/mm3/mailman3/lists/sfepy.python.org/ Git (source) repository, issue tracker: https://github.com/sfepy/sfepy Highlights of this release -- - support preconditioning in SciPy and PyAMG based linear solvers - user-defined preconditioners for PETSc linear solvers - parallel multiscale (macro-micro) homogenization-based computations - improved tutorial and installation instructions For full release notes see http://docs.sfepy.org/doc/release_notes.html#id1 (rather long and technical). Cheers, Robert Cimrman --- Contributors to this release in alphabetical order: Robert Cimrman Lubos Kejzlar Vladimir Lukes Matyas Novak ___ NumPy-Discussion mailing list NumPy-Discussion@python.org https://mail.python.org/mailman/listinfo/numpy-discussion
Re: [Numpy-discussion] [SciPy-User] ANN: SciPy 1.0 beta release
On Mon, Sep 18, 2017 at 10:36 PM, Matthew Brett wrote: > Hi, > > On Mon, Sep 18, 2017 at 11:14 AM, Ralf Gommers > wrote: > > > > > > On Mon, Sep 18, 2017 at 10:11 PM, Matthew Brett > > > wrote: > >> > >> Hi, > >> > >> On Mon, Sep 18, 2017 at 11:07 AM, Thomas Kluyver > wrote: > >> > On 18 September 2017 at 10:59, Ralf Gommers > >> > wrote: > >> >> > >> >> Binary wheels for Windows, Linux and OS X (for all supported Python > >> >> versions, 32-bit and 64-bit) can be found at http://wheels.scipy.org > . > >> >> To > >> >> install directly with pip: > >> >> > >> >> pip install scipy=='1.0.0b1' -f http://wheels.scipy.org > >> >> --trusted-host > >> >> wheels.scipy.org > >> > > >> > > >> > I don't want to criticise the hard work that has gone into making this > >> > available, but I'm disappointed that we're telling people to install > >> > software over an insecure HTTP connection. > >> > >> I personally prefer the following recipe: > >> > >> pip install -f > >> https://3f23b170c54c2533c070-1c8a9b3114517dc5fe17b7c3f8c63a4 > 3.ssl.cf2.rackcdn.com > >> scipy=='1.0.0b1' > >> > >> > Can the wheels not be uploaded to PyPI? > >> > >> Sounds like a good idea. I can do that - any objections? > > > > > > That would be helpful Matthew, I'm about to sign off for today. > > Done - new instructions for testing: > > pip install --pre --upgrade scipy > Thanks Matthew! Replying to all lists with the better install instructions. Cheers, Ralf ___ NumPy-Discussion mailing list NumPy-Discussion@python.org https://mail.python.org/mailman/listinfo/numpy-discussion