Page 2 of 2 FirstFirst 12
Results 11 to 14 of 14

Thread: PCARS SharedMemory API - Documentation/Reference?

  1. #11
    Kart Driver
    Join Date
    Jul 2015
    Location
    Ribe
    Posts
    12
    Platform
    PC
    Hi,

    From the structure provided by Mad Al I am trying to read the MemoryMappedFile, but am receiving an error “The specified Type must be a struct containing no reference”
    The error comes from the Function ReadMemoryMappedFile - a.Read(0, c)
    How do I correct this error?

    Thank you in advance,
    Henrik

    Code:
    Private Function ReadMemoryMappedFile(ByVal Name As String) As Byte()
    
            Try
                Using MemoryFile As IO.MemoryMappedFiles.MemoryMappedFile =
                    IO.MemoryMappedFiles.MemoryMappedFile.OpenExisting(Name, IO.MemoryMappedFiles.MemoryMappedFileRights.ReadWrite)
    
                    Dim a As System.IO.MemoryMappedFiles.MemoryMappedViewAccessor
                    a = MemoryFile.CreateViewAccessor()
    
                    If a.CanRead = True Then
                        Dim c As New MMFContents
                        a.Read(0, c) 'Læser alle data fra position 0 ind i c
                End Using ' MemoryFile
    
            Catch exNoFile As IO.FileNotFoundException
                Throw
                Return Nothing
    
            Catch ex As Exception
                Throw
    
            End Try
    
        End Function

  2. #12
    WMD Member pock1910's Avatar
    Join Date
    Oct 2011
    Posts
    219
    Platform
    PC
    I read the MemoryMappedFile with this code (C#):

    Code:
    private MemoryMappedFile mMemMapFile = null;
    
    try
    {   mMemMapFile = MemoryMappedFile.OpenExisting("$pcars$");
    }
    catch (Exception)
    { ...
    }
    
    
    if (mMemMapFile != null)
    {
        using (var SharedMemoryStreamView = mMemMapFile.CreateViewStream())
        {
            int pCarsDataSharedMemorySize = Marshal.SizeOf(typeof(SharedMemoryPCARS));
            byte[] SharedMemoryReadBuffer = new byte[pCarsDataSharedMemorySize];
    
            BinaryReader brSharedMemoryStream = new BinaryReader(SharedMemoryStreamView);
            SharedMemoryReadBuffer = brSharedMemoryStream.ReadBytes(pCarsDataSharedMemorySize);
            GCHandle handle = new GCHandle();
            try
            { handle = GCHandle.Alloc(SharedMemoryReadBuffer, GCHandleType.Pinned);
            }
            catch (Exception e)
            {   Tools.WriteLine("Fehler bei GCHandle.Alloc (SharedMemory) - Detail: " + e.Message);
                Environment.Exit(0);
            }
            MMF = (SharedMemoryPCARS)Marshal.PtrToStructure(handle.AddrOfPinnedObject(), typeof(SharedMemoryPCARS));
            handle.Free();
        }
    }
    CPU: Intel i7 4790 | GPU: Nvidia GTX 970 | RAM: 8GB | OS: Windows 10
    Wheel: Logitech G27 Monitor: Benq XL2420T | Helmet view with FOV 60

    Website - POCK Race Trainer for PROJECT CARS
    Forum - POCK Race Trainer for PROJECT CARS

  3. #13
    Kart Driver
    Join Date
    Jul 2015
    Location
    Ribe
    Posts
    12
    Platform
    PC
    Thank you very much pock1910. In the meantime I translated the code from MikeyTT, but I will for sure try yours too.

  4. #14
    Kart Driver TylerDurden4321's Avatar
    Join Date
    May 2015
    Location
    Bremen
    Posts
    8
    Platform
    XBOX1
    I'm not a WMD member, so I have to ask here in the official forum:

    Are there any new channels that the Project CARS 2 API will put through?
    I'm especially interested in individual tire loads/normal forces, slip angles (slip ratios are put out already) and tire temps with three lanes per tire (inner/mid/outer) for camber setting or at least tire pressure.

    Big thanks for any info in advance

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •