The online racing simulator
Searching in All forums
(4 results)
GReeDy_PL
Demo licensed
When i use that piece of code "rpmBytes = "{.1f}".format(rpm).encode("latin1")
ser.write(rpmStr)"

unfortunately, i got that error "AttributeError: 'float' object has no attribute '1f'"

Problem is, in these pack they are in float, i can send car pack, cause ( i think ), its in ASCII.So, my solve is convert floats to ints.
GReeDy_PL
Demo licensed
Sorry for my rude behavior.My python ver is 2.7.Spaces, between rpm and parentesis didnt make a diffrence.Yes, i got data from "print" fuction in float.And third, its a problem, when I even convert float, to int or string, i got the all time the same result "float' object is not iterable"
GReeDy_PL
Demo licensed
Quote from Skinzinho :Why are you requesting Python support on LFS forum?

Anyway, as I can see, you dont open/close your serial connection. Try to add the following:

if not ser.isOpen():
ser.open()
print('COM3 IS NOW OPENED', ser.isOpen())


Then, you should have your serial connection opened. If not, it means something else is using COM3. If my code works for you, dont forget to close the serial after script ending.


EDIT: Could you share a photo of what you have done already? I'm trying to build something similar, just for fun.

Did you excatlly readed my post ? I got opened COM3 (and its use by arduino), cause when i sending car pack ( outgauge_pack[1] ), i got data on my LCD ( name of car, which i got now ), but when i want send RPM pack or other pack besides car pack, i got that "float' object is not iterable".Error of "COM is close, acces is denied" is my bad, just when runing program i got that error, cause i have to wait a while to open port, for next run of program.So, my problem is that error "float' object is not iterable".

And yes, i can send u photos, but its only alfanumeric LCD, pluged to arduino, nothing more.
Last edited by GReeDy_PL, .
Strange problem with outgauge, and arduino
GReeDy_PL
Demo licensed
Hello, i got strange problem with sending outgaugepack through serial, when ill send car pack, everything is good, and on my LCD i got data, but when i want send rpm pack or other pack, through serial, i cant, cause python give me that error "SerialException: could not open port 'COM3': WindowsError(5, acces is denied".Its very strange, cause when I sending car pack, everything works properly.

CODE

import socket
import struct
import serial
ser = serial.Serial(2, 115200)

sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)

sock.bind(('127.0.0.1', 3))

while True:

data = sock.recv(256)

if not data:
break


outgauge_pack = struct.unpack('I3sxH2B7f2I3f15sx15sx', data)
time = outgauge_pack[0]
car = outgauge_pack[1]
flags = outgauge_pack[2]
gear = outgauge_pack[3]
speed = outgauge_pack[5]
rpm = outgauge_pack[6]
turbo = outgauge_pack[7]
engtemp = outgauge_pack[8]
fuel = outgauge_pack[9]
oilpressure = outgauge_pack[10]
oiltemp = outgauge_pack[11]
dashlights = outgauge_pack[12]
showlights = outgauge_pack[13]
throttle = outgauge_pack[14]
brake = outgauge_pack[15]
clutch = outgauge_pack[16]
display1 = outgauge_pack[17]
display2 = outgauge_pack[18]
ser.write( rpm )

sock.close()
FGED GREDG RDFGDR GSFDG